Discord.js 用随机消息欢迎新用户的机器人
Discord.js bot that welcomes new users with a random message
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}!`);
});
这有效,但它只发出一条消息...我希望能够随机将一条随机消息发送到欢迎频道。我对创建机器人还很陌生。
您可以做的是创建一组答案,然后从中随机选择一个,如下所示:
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)]);
});
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}!`);
});
这有效,但它只发出一条消息...我希望能够随机将一条随机消息发送到欢迎频道。我对创建机器人还很陌生。
您可以做的是创建一组答案,然后从中随机选择一个,如下所示:
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)]);
});