所以当新成员加入时Guild
[不和谐服务器]。机器人应该在某个频道(ID = 766716351007686696)发送消息,向他们发送直接消息,然后添加角色(Human Bean)。这是我现在拥有的代码,它不起作用,底部有错误
client.on('guildMemberAdd', member =>{
const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")
const channelwelcomeEmbed = new Discord.MessageEmbed()
.setColor('#ffd6d6')
.setTitle('Welcome!')
.setDescription(`${member} just joined the discord! Make sure to read #rules!`)
.setTimestamp();
channel.send(channelwelcomeEmbed);
const dmwelcomeEmbed = new Discord.MessageEmbed()
.setColor('#ffd6d6')
.setTitle('Welcome!')
.setDescription("For Help Using @Pro Bot#7903, Send The Command `!help` In Server")
.setTimestamp();
member.send(dmwelcomeEmbed);
let role6 = message.guild.roles.cache.find(role => role.name == "Human Bean"); //BASIC ROLE, EVERYONE GETS IT
if(!role6) return message.reply("Couldn't find that Role .")
member.roles.add(role6);
});
错误消息是;
const channel = message.guild.channels.cache.find(c => c.id === "766716351007686696")
^
ReferenceError: message is not defined
您的代码看起来不错,问题是未触发该事件。那是因为不和谐默认关闭了“特权意图”。
由于数据的敏感性,某些意图被定义为“特权”。这些意图是:
GUILD_PRESENCES
GUILD_MEMBERS
其中一个影响就是你所经历的,不工作guildMemberAdd
event.
好消息是您只需一个简单的步骤即可解决此问题。只需启用特权网关意图 in the Discord 开发者门户它应该工作得很好。
如果您想了解更多相关信息
- Discord.js 官方指南 - 网关意图
- Discord 开发者文档 - 网关意图
- 网关更新常见问题解答
- Discord API Github - 问题 1363 - 特权意图
- Discord 博客 - Discord 机器人的未来
- 我的discord.js guildmember 事件都没有发出,我的用户缓存基本上是空的,并且我的函数超时了?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)