Discord机器人程序记录用户服务器加入的剩余信息



我的代码:

//Welcome & goodbye messages\
client.on('guildMemberAdd', member => {
member.roles.add(member.guild.roles.cache.find(i => i.name === 'Among The Server'))
const welcomeEmbed = new Discord.MessageEmbed()
welcomeEmbed.setColor('#5cf000')
welcomeEmbed.setTitle('**' + member.user.username + '** is now Among Us other **' + member.guild.memberCount + '** people')
welcomeEmbed.setImage('https://cdn.mos.cms.futurecdn.net/93GAa4wm3z4HbenzLbxWeQ-650-80.jpg.webp')
send.message.channel("767685428018413571").send(welcomeEmbed)
})
client.on('guildMemberRemove', member => {
const goodbyeEmbed = new Discord.MessageEmbed()
goodbyeEmbed.setColor('#f00000')
goodbyeEmbed.setTitle('**' + member.user.username + '** was not the impostor there are **' + member.guild.memberCount + '** left Among Us')
goodbyeEmbed.setImage('https://gamewith-en.akamaized.net/article/thumbnail/rectangle/22183.png')
send.message.channel("767685428018413571").send(goodbyeEmbed)
})
//Welcome & goodbye messages end\

我将使用我的测试帐户加入测试服务器。和机器人不发送消息,你是加入服务器等

请帮帮我。

提前感谢

问题出在send.message.channel这一行。Send没有定义,您需要先定义通道,然后发送embebed消息。

const channel = client.channels.cache.get("767685428018413571");
channel.send(welcomeEmbed);

我希望你觉得有用

编辑

如果您更喜欢使用名称通道

const channelName = 'Name of the channel'
const channel = client.channels.cache.find(channel => channel.name === channelName)
channel.send(welcomeEmbed);

通常我使用.env来访问环境变量,如通道名称

const channel = client.channels.cache.find(channel => channel.name === process.env.CHANNEL_NAME)
channel.send(welcomeEmbed);

最新更新