Javascript 使用 discord.js 加入 discord 服务器时的欢迎信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49759835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Welcome message when joining discord Server using discord.js
提问by Skwal
I am making a discord bot using node.js and discord.js, and I am currently trying to make it so that when a user joins the discord server, a custom welcome message is sent. Here is my code:
我正在使用 node.js 和 discord.js 制作一个 discord bot,我目前正在尝试制作它,以便当用户加入 discord 服务器时,发送自定义欢迎消息。这是我的代码:
bot.on("guildMemberAdd" ,(message, member) => {
message.channel.send("Welcome")
});
This is the error is get:
这是得到的错误:
message.channel.send("Welcome")
^
TypeError: Cannot read property 'send' of undefined
Thanks for your help.
谢谢你的帮助。
回答by Skwal
If you read the documentation, there's is no messageparameter, only member. You will have to get the guild's channelID first.
如果您阅读文档,则没有message参数,只有member. 您必须先获得公会的频道ID。
Try something like this:
尝试这样的事情:
bot.on('guildMemberAdd', member => {
member.guild.channels.get('channelID').send("Welcome");
});
回答by lol
Or use this for embeds.
或者将其用于嵌入。
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"
}
}}); });
}}); });
回答by iCodeAlot
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"
}
}}); });
Here is code that actually works :)
这是实际工作的代码:)

