Reputation: 13
client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.find(ch => ch.name === 'welcome');
if (!channel) return;
channel.send(`Welcome to the community, ${member}!`);
});
This works but it only gives out one message... I'd like the ability to have one random message at random to be send to the welcome's channel. I'm very new to creating bots.
Upvotes: 1
Views: 286
Reputation: 1245
What you could do is create an array of answers and then pick one from that at random, like this:
const answers = ["Welcome to the community", "We hope you brought pizza", "etc."];
client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.find(ch => ch.name === 'welcome');
if (!channel) {
return; //Or do something else here ;)
}
return channel.send(answers[Math.floor(Math.random() * answers.length)]);
});
Upvotes: 2