[英]Discord.js Bots // Welcome function not working
So I was trying to code my bot to execute different welcome messages if a player joins the server.所以我试图编写我的机器人来在玩家加入服务器时执行不同的欢迎消息。 The bot is not stating any issue in the code but every time someone joins, nothing happens, it just appears in the logs.
机器人没有在代码中说明任何问题,但每次有人加入时,什么也没有发生,它只是出现在日志中。 Any clues?
有什么线索吗?
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);
});
};
Theres a few errors in your code so I'll just try to fix them for you.您的代码中存在一些错误,因此我会尝试为您修复它们。 This version should definitely work anyways.
无论如何,这个版本肯定可以工作。
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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.