[英]How do I get my Discord bot to send a welcome message?
I've watched numerous videos, and followed examples online, and still can't get my discord bot to simply send a message upon a member joining.我看过很多视频,并在网上关注示例,但仍然无法让我的 discord 机器人在会员加入时简单地发送消息。 Maybe I'm missing out on an important update?也许我错过了一个重要的更新?
//require the necessary discord.js classes
const { Client, Intents } = require("discord.js");
const { token } = require("./config.json");
//create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
//when the client is ready, run this code (only once)
client.on('ready', () => {
console.log("Online");
});
//sends user a welcome message upon joining
client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.get('921490782958014576');
channel.send("Welcome to the server!!")
});
client.login(token);
I get nothing.我什么都得不到。 Nada.纳达。 I've tried several different pieces of code.我已经尝试了几段不同的代码。 I've TRIPLE checked the permissions.我已经三重检查了权限。 This is very frustrating.这非常令人沮丧。 I've tried unadding and readding the bot to the server.我已经尝试将机器人取消添加并将其读取到服务器。 I checked up on the discord.js documentation and nothing seems to be wrong with my code.我检查了 discord.js 文档,我的代码似乎没有任何问题。 To me it seems as if the guildMemberAdd isn't emitting anything.对我来说,好像 guildMemberAdd 没有发出任何东西。 I'm using notepad++ to edit my code.我正在使用记事本++ 来编辑我的代码。 I feel I could be using something better for debugging purposes possibly.我觉得我可能会使用更好的东西来进行调试。
The issue may be due to missing intents.该问题可能是由于缺少意图。 Try adding the GUILD_MEMBERS
intent to your list of intents like so.尝试像这样将GUILD_MEMBERS
意图添加到您的意图列表中。
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] });
discord.js docs: https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS discord.js 文档: https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS
Developer docs: https://discord.com/developers/docs/topics/gateway#gateway-intents开发者文档: https://discord.com/developers/docs/topics/gateway#gateway-intents
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.