Discord.js Bots//欢迎功能不起作用



所以我试图对我的机器人进行编码,以便在玩家加入服务器时执行不同的欢迎消息。机器人程序没有在代码中说明任何问题,但每次有人加入时,都不会发生任何事情,只是出现在日志中。有线索吗?

module.exports = (client) => {
const channelId = '766761508427530250'; // welcome channel
client.on('guildMemberAdd', (member) => {
console.log(member);
const welcomes = [
`The member <@${member.id}> is joining us, welcome to ${member.guild}!`,
`Say hello to <@${member.id}> Welcome to ${member.guild}!`,
`Cheers, ${member}, welcome to the server!`,
`I am smelling newcomers! Welcome, ${member} to ${member.guild}!`,
];
const message = `${
welcomes[Math.floor(Math.random() * welcomes.length)]
} Please read the ${member.guild.channels.cache.get(
'766731745960919052'
)} and click on verify to gain full access to the server.`;
const channel = member.guild.channels.cache.get(channelId);
channel.send(message);
});
};

您的代码中有一些错误,所以我将尝试为您修复它们。无论如何,这个版本肯定会起作用。

client.on('guildMemberAdd', member => {
console.log(member);
const welcomes = [
`The member ${member} is joining us, welcome to ${member.guild}!`,
`Say hello to ${member.id} Welcome to ${member.guild}!`,
`Cheers, ${member}, welcome to the server!`,
`I am smelling newcomers! Welcome, ${member} to ${member.guild}!`
];
const message = `${welcomes[~~(Math.random() * welcomes.length)]} Please read the <#766731745960919052> and click on verify to gain full access to the server.`;
const channelId = '766761508427530250'; // welcome channel
const channel = member.guild.channels.cache.find(chan => chan.id === `${channelId}`);
channel.send(message);
});

最新更新