Je crée un bot discord en utilisant node.js et discord.js, et j'essaie actuellement de faire en sorte que lorsqu'un utilisateur se connecte au serveur discord, un message de bienvenue personnalisé soit envoyé. Voici mon code:
bot.on("guildMemberAdd" ,(message, member) => {
message.channel.send("Welcome")
});
C'est l'erreur est get:
message.channel.send("Welcome")
^
TypeError: Cannot read property 'send' of undefined
Merci de votre aide.
Si vous lisez la documentation , il n'y a pas de paramètre message
, seulement member
. Vous devrez obtenir d'abord l'identifiant du canal de la guilde.
Essayez quelque chose comme ça:
bot.on('guildMemberAdd', member => {
member.guild.channels.get('channelID').send("Welcome");
});
client.on('guildMemberAdd', member => {
client.on('message',
var role = member.guild.roles.find('name', 'Beginner role name'); // Variable to get channel ID
member.addRole(role); // Adds the default role to members
member.guild.channels.get('JOIN/LEAVE Channel ID').send({embed: {
color: 3447003,
title: "**SERVER NAME** Welcome Bot!",
url: "WEBSITE URL",
description: "Welcome *" + member + "* to the **Server name** discord server!",
fields: [{
name: "Information",
value: "Some info on the server"
}
],
timestamp: new Date(),
footer: {
icon_url: client.user.avatarURL,
text: "© NAME OF SERVER 2018 - 2019"
}
}}); });
Voici le code qui fonctionne réellement :)
Ou utilisez ceci pour les embed.
client.on('guildMemberAdd', msg => { // Commands Go Inside The client.on('message',
msg => )
msg.guild.channels.get('484648408372740099').send({embed: {
color: 3447003,
author: {
name: client.user.username,
icon_url: client.user.avatarURL
},
title: "Welcome To ()!",
url: "https://districtservices.net",
description: "@MEMBER",
fields: [{
name: "Fields",
value: "They can have different fields with small headlines."
},
{
name: "Masked links",
value: "You can put [masked links](http://google.com) inside of rich embeds."
},
{
name: "Markdown",
value: "You can put all the *usual* **__Markdown__** inside of them."
}
],
timestamp: new Date(),
footer: {
icon_url: client.user.avatarURL,
text: "© Example"
}
}}); });