【发布时间】:2020-09-06 01:36:23
【问题描述】:
现在我正在制作一个不和谐机器人(discord.js 版本 12)。
它是这样工作的:
- 有人发送和侮辱
- 如果侮辱包含在列表中(存储在
insultes.json),机器人会发送消息并添加反应 - 如果我们添加相同的反应,机器人会发送另一条消息
我面临的问题是,如果我继续添加反应,机器人会继续回复 2、3、4 次等等:每次 (n) 我检查它回复的 n+1 条消息的反应。
这是代码:
bot.on('message', message => {
const insulte = require('./insultes.json');
for (let p = 0; p < insulte.length; p++) {
// Check if the insult is in the list and make sure it's not from the bot itself
if (message.content.toLowerCase().includes(insulte[p]) && message.author.id !== "711337757435363468") {
message.channel.send("First message").then(messageReaction => {
messageReaction.react("➡️");
});
bot.on('messageReactionAdd', (reaction, user) => {
if (reaction.emoji.name === "➡️" && user.id !== "711337757435363468") {
message.channel.send("Additional message");
}
});
}
}
});
【问题讨论】:
标签: node.js discord.js