【问题标题】:Discord.js bot that welcomes new users with a random messageDiscord.js 机器人通过随机消息欢迎新用户
【发布时间】:2021-01-22 09:12:38
【问题描述】:
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}!`);
});

这可行,但它只发出一条消息...我希望能够随机发送一条随机消息发送到欢迎频道。我对创建机器人非常陌生。

【问题讨论】:

    标签: random discord bots message


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-13
      • 2020-05-18
      • 1970-01-01
      • 2018-02-07
      • 1970-01-01
      • 2021-10-07
      • 2020-01-22
      • 2021-02-22
      • 1970-01-01
      相关资源
      最近更新 更多