[英]code to console log members joining isnt working in discord.js
I have been half following a tutorial, half working it out on my own how to code a discord bot in discord.js.我一直在学习一个教程,一半在自己研究如何在 discord.js 中编写 discord 机器人。 I am up to the point where i want to add a welcome message, and after doing the same thing as the person making the tutorial the code isn't console logging a joining member to the server.
我已经到了要添加欢迎消息的地步,并且在做与制作教程的人相同的事情之后,代码不是控制台将加入的成员记录到服务器。 Here is the code that i have done, and in the tutorial the code would send a welcome message to the selected channel and console log the member.
这是我已经完成的代码,在教程中,代码将向所选频道发送欢迎消息并控制台记录成员。
there is no error message没有错误信息
module.exports = client => {
const channelId = '790887807127650304' // welcome channel
client.on('guildMemberAdd', member => {
console.log(member)
const message = `welcome <@${member.id} to the server!`
const channel = member.guild.channels.cache.get(channelID)
channel.send(message)
})
}
also, for reference, here is the tutorial i have been following;另外,作为参考,这是我一直在关注的教程; video
视频
Make sure the gateway intents are enabled in your dev portal for your bot, it's in the bot tab (the same page where you copy the bot's token).确保在您的机器人的开发门户中启用网关意图,它位于机器人选项卡中(复制机器人令牌的同一页面)。 This is a change made after the tutorial you linked.
这是您链接教程后所做的更改。
If you want to know why this is required, read this 如果您想知道为什么需要这样做,请阅读此
Also there are a few errors in your code.您的代码中也有一些错误。 You typed channelID two different ways and you didnt put '>' after
<@${member.id}
.您以两种不同的方式输入了 channelID,并且没有在
<@${member.id}
之后放置“>”。
Here it is fixed.这里是固定的。
module.exports = client => {
const channelID = '790887807127650304' // welcome channel
client.on('guildMemberAdd', member => {
console.log(member)
const message = `welcome <@${member.id}> to the server!`
const channel = member.guild.channels.cache.get(channelID)
channel.send(message)
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.