[英]Discord.js awaitmessage error, how to fix?
I was making this new bot and used awaitmessage function.When a user use the cmd ',gangsug'.我正在制作这个新机器人并使用 awaitmessage function。当用户使用 cmd ',gangsug' 时。 the bot is supposed to ask a question like - "Please choose a option - RP or Fight" and when the user uses an option it is supposed to give a reply.机器人应该问一个问题,比如“请选择一个选项 - RP 或战斗”,当用户使用一个选项时,它应该给出回复。 (Which is a embed one). (这是一个嵌入)。 I have given two different replies for the 2 answers given by the user.(One for the answer "RP" and the other for the answer "Fight"), In this case.对于用户给出的 2 个答案,我给出了两种不同的答复。(一个用于回答“RP”,另一个用于回答“Fight”),在这种情况下。 by bot is giving same answer for both answer. by bot 对两个答案都给出了相同的答案。 If the user types "RP" or "Fight" same reply is being given by the bot.如果用户键入“RP”或“Fight”,则机器人会给出相同的回复。 I hope you understood the problem.The code will be given below (ofc only the part where the problem comes)我希望你理解这个问题。代码将在下面给出(ofc只有问题出现的部分)
if (message.content === `${prefix}gangsug`) {
message.reply('Hey there! Please choose a option.\n'
+ 'Confirm with `RP` or with `Fight`.');
// First argument is a filter function - which is made of conditions
// m is a 'Message' object
message.channel.awaitMessages(m => m.author.id == message.author.id,
{max: 1, time: 30000}).then(collected => {
// only accept messages by the user who sent the command
// accept only 1 message, and return the promise after 30000ms = 30s
// first (and, in this case, only) message of the collection
if (collected.first().content.toLowerCase() == 'RP') {
message.reply(suggestgang1);
}
else
message.reply(suggestgang2);
message.reply(suggestgang3);
}).catch(() => {
message.reply('No answer after 30 seconds, req canceled.');
});
} }
);
**Yea, this is the code..It would be great of you give an answer by stating the problem and a fixed code to replace this one. **是的,这是代码。如果您能通过说明问题和替换此代码的固定代码来给出答案,那就太好了。 Thank you:) **谢谢:) **
I believe the problem is in this line:我相信问题出在这一行:
if (collected.first().content.toLowerCase() == 'RP')
Since you used the .toLowerCase()
method on the message content, it's physically impossible to match anything uppercase, such as 'RP'.由于您在消息内容上使用了.toLowerCase()
方法,因此在物理上不可能匹配任何大写字母,例如“RP”。
if (collected.first().content.toLowerCase() == 'rp')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.