Discord.js机器人通过随机消息欢迎新用户

时间:2020-10-07 12:01:44

标签: random discord bots message

GztTerm

此方法有效,但只发出一条消息...我希望能够随机发送一条随机消息以发送到欢迎频道。我对创建机器人很陌生。

1 个答案:

答案 0 :(得分:2)

您可以做的是创建一个答案数组,然后从中随机选择一个,如下所示:

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)]);
});