[英]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.