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);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.