Skip to content
Snippets Groups Projects
Commit 0d0398cc authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

WebhookClient

parent fd28b343
No related branches found
No related tags found
No related merge requests found
......@@ -242,7 +242,7 @@ recursiveAsyncReadLine(); //we have to actually start our recursion somehow
// BOT DISCORD
////////////////////////////////////////////////////////////////
// require the needed discord.js classes
const { Client, Intents, MessageActionRow, MessageButton } = require('discord.js');
const { Client, Intents, MessageActionRow, MessageButton, WebhookClient } = require('discord.js');
const { verify } = require('crypto');
// create a new Discord client
......@@ -461,9 +461,7 @@ async function verifyMcChatWebhook(){
console.log("[" + 'INFO'.yellow + "] Le Webhook du serveur MC est déjà configuré.");
let mcChatWebhookToken = await botSettings.findOne({ where: { name: "mcChatWebhookToken" } });
if(mcChatWebhookToken){
mcChatWebhook = client.fetchWebhook(mcChatWebhookId.value, mcChatWebhookToken.value)
.then(webhook => console.log("[" + 'INFO'.yellow + "] Webhook " + webhook.name + " trouvé."))
.catch(console.error);
mcChatWebhook = new WebhookClient({ id: mcChatWebhookId.value, token: mcChatWebhookToken.value });
}else{
console.log("[" + 'ERREUR'.brightRed + "] Impossible de trouver le token du webhook dans la base de donnée.");
createMcChatWebhook();
......@@ -487,16 +485,13 @@ async function createMcChatWebhook(){
name: "mcChatWebhookToken",
value: webhook.token
});
mcChatWebhook = client.fetchWebhook(mcChatWebhookId.value, mcChatWebhookToken.value)
.then(webhook => console.log("[" + 'INFO'.yellow + "] Webhook " + webhook.name + " trouvé."))
.catch(console.error);
mcChatWebhook = new WebhookClient({ id: mcChatWebhookId.value, token: mcChatWebhookToken.value });
console.log("[" + 'INFO'.yellow + "] Le Webhook du serveur MC a été configuré avec succès.");
})
.catch(console.error);
}
function sendMessageFromMcChat(username, message){
console.log(mcChatWebhook);
mcChatWebhook.send({
content: message,
username: username,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment