简体   繁体   English

如何让我的 discord 机器人通过回复池回复特定消息?

[英]How do I make my discord bot reply to a specific message with reply from a pool of replies?

Pretty much all in the title.几乎都在标题中。 I want my bot to respond with a random reply from a pool of replies.我希望我的机器人从回复池中随机回复。 This is what I have so far:这是我到目前为止所拥有的:

const Discord = require('discord.js');
const bot = new Discord.Client();

bot.on('ready', () =>{
    console.log('Just Chillin');
    bot.user.setActivity('Working' , { type: 'BotOn'}).catch(console.error);

}); 

function randomMessage(){
    var randomNumber = Math.round(Math.random()*2); // 0, 1 or 2
    switch(randomNumber){
        case 0: return 'Hello!';
        case 1: return 'Hi!';
        case 2: return 'Hola';
    }
}

bot.on('message' , message => {
    if(message.content.toLowerCase().includes('ping'))
        message.reply('pong')
    else if(message.content.toLowerCase().includes('Hello'))
            message.reply(randomMessage());
});

Also, I do not have much experience in Java, only R, so I was also wondering where you would put the first chunk of code.另外,我在 Java 方面没有太多经验,只有 R,所以我也想知道你会把第一块代码放在哪里。 Would you put it below or above the bot.on('message', message=> ? Also, when I have that code entered, nothing happens and everything else runs fine.你会把它放在bot.on('message', message=>下方还是上方?另外,当我输入该代码时,没有任何反应,其他一切都运行良好。

Thank you in advance.先感谢您。 I apologize for my lack of Java knowledge.对于我缺乏 Java 知识,我深表歉意。

When I want pick a random message (like 8ball), I always do it this way:当我想选择一条随机消息(如 8ball)时,我总是这样做:

Define different options:定义不同的选项:

let options = ["Hey", "Hello there!", "Hey, it's me!", "NOT NOW IM BUSY"];

Pick a random message:选择一条随机消息:

let result = options[Math.floor(Math.random() * options.length)];

Log the result:记录结果:

console.log(result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让我的 discord 机器人回复包含特定字母/字符的消息? - How can I make my discord bot reply to a message when it contains a specific letter/character? 如何使Discord bot DM用户获得特定答复? - How do I make my Discord bot DM users with a specific reply? 如何让我的 Discord Bot 回复并提及? - How to make my Discord Bot reply with a mention? 我怎样才能让机器人回复一条由我不和谐的回复的消息 - How can i make the bot reply to a message which is a reply by me discord 如何让 DIscord.js 机器人实际回复消息? - How do I make a DIscord.js bot actually reply to a message? 如何使 Telegram BOT 回复特定消息? - How to make Telegram BOT reply to a specific message? 如何让我的 Discord Bot 回复类似消息的相同答案? JavaScript - How do I make my Discord Bot reply a same answer for similar messages? JavaScript 如何让我的机器人等待提到的用户 discord.js 的回复? - How do I get my bot to wait for reply from a mentioned user discord.js? 如何让 discord 机器人检查消息的内容并根据作者回复不同的消息? - How can I make a discord bot check the contents of a message and reply with a different message depending on the author? 当被问到某个问题时,如何让我的 Discord Bot (Javascript) 在标签中回复用户? - How can i make my Discord Bot (Javascript) reply to the user in tag, when a certain question is asked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM