[英]Have a discord bot send many messages with only one command
I am making a cultist bot for discord, and I want it to send a message that repeats a message five times when an appropriate command is given !praise . 我正在制作一个不和谐的文化机器人,我希望它在给出适当的命令时发送一条重复消息五次的消息!赞 。
All the other commands run correctly (below I put one such command, !saviour , as an example), however, the !praise command never gives any output. 所有其他命令都正确运行(下面我放了一个这样的命令, `救世主 ,作为一个例子),然而, !praise命令永远不会给出任何输出。
I was hoping it would iterate through the loop, sending a message each time, as you would expect from a for
loop. 我希望它会遍历循环,每次都发送一条消息,正如你
for
循环所期望的那样。
What stops the loop from running and how can I fix it? 什么阻止循环运行,我该如何解决?
bot.on('message', function(user, userID, channelID, message, evt) {
if (message.substring(0, 1) === '!') {
let args = message.substring(1).split(' ');
let cmd = args[0];
args = args.splice(1);
switch (cmd) {
case 'saviour':
bot.sendMessage({
to: channelID,
message: 'Our current lord and saviour is named asghjahero'
});
break; //the above case works fine
case 'praise':
for (let i = 1; i === 5; i++) {
bot.sendMessage({
to: channelID,
message: 'All Hail!'
});
}
break;
}
}
});
要回答标题中的问题,您只需在侦听器中运行bot.sendMessage
两次。
Take a look at the condition in your for
loop ( i === 5
). 看看
for
循环中的条件( i === 5
)。 The loop will execute as long as that's true. 只要这是真的,循环就会执行。 But you start the loop off by assigning
i = 1
, and 1 is not equal to 5, even for large values of 1. 但是你通过指定
i = 1
启动循环,并且1不等于5,即使对于大的值1也是如此。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.