如何忽略前两个机器人反应?
How to ignore the first 2 bot reactions?
我正在尝试测试何时有人对机器人在嵌入中发布的 2 个表情符号之一做出反应,但是当机器人在嵌入中做出反应时,它会触发 if (reaction.emoji.name === ' ') 声明,我不确定如何忽略机器人的前 2 个反应,人们可以对这些反应做出反应
let msg2 = await orderChannel.send({embed: embed});
msg2.react('✅');
msg2.react('');
const reactions = await msg2.awaitReactions(reaction => reaction.emoji.name == '✅' || reaction.emoji.name == '', {time: 86400000, max: 1});
let reaction = await reactions.first();
if (reaction.emoji.name === '✅') {
await msg2.delete();
await msg.author.send(`Your order was completed. Please come to the pharmacy with $ ${howmany}000`);
return;
};
if (reaction.emoji.name === '') {
await msg2.delete();
await msg.author.send(`Your order has been delayed, please message Pixel for info.`);
return;
};
};
我能想到的最快解决方法是使用 MessageReaction.count
属性,它会计算消息中相关反应的数量。在你的情况下,你可能会说
if (reaction.emoji.name === '✅' && reaction.count > 1) {. . .}
我认为这最有效。过滤器检查支票表情符号和作者或 D 表情符号和作者。因此,如果机器人或与此相关的任何其他人做出反应,它就会忽略它。
let filter = (reaction, user) => reaction.emoji.name == '✅' && user.id == msg.author.id || reaction.emoji.name == '' && user.id == msg.author.id;
const reactions = await msg2.awaitReactions(filter, {time: 86400000, max: 1});
This works well as AND (&&) executes before OR (||).
我还稍微调整了格式,使其更易于阅读。 (分隔成一个过滤器变量)
我正在尝试测试何时有人对机器人在嵌入中发布的 2 个表情符号之一做出反应,但是当机器人在嵌入中做出反应时,它会触发 if (reaction.emoji.name === ' ') 声明,我不确定如何忽略机器人的前 2 个反应,人们可以对这些反应做出反应
let msg2 = await orderChannel.send({embed: embed});
msg2.react('✅');
msg2.react('');
const reactions = await msg2.awaitReactions(reaction => reaction.emoji.name == '✅' || reaction.emoji.name == '', {time: 86400000, max: 1});
let reaction = await reactions.first();
if (reaction.emoji.name === '✅') {
await msg2.delete();
await msg.author.send(`Your order was completed. Please come to the pharmacy with $ ${howmany}000`);
return;
};
if (reaction.emoji.name === '') {
await msg2.delete();
await msg.author.send(`Your order has been delayed, please message Pixel for info.`);
return;
};
};
我能想到的最快解决方法是使用 MessageReaction.count
属性,它会计算消息中相关反应的数量。在你的情况下,你可能会说
if (reaction.emoji.name === '✅' && reaction.count > 1) {. . .}
我认为这最有效。过滤器检查支票表情符号和作者或 D 表情符号和作者。因此,如果机器人或与此相关的任何其他人做出反应,它就会忽略它。
let filter = (reaction, user) => reaction.emoji.name == '✅' && user.id == msg.author.id || reaction.emoji.name == '' && user.id == msg.author.id;
const reactions = await msg2.awaitReactions(filter, {time: 86400000, max: 1});
This works well as AND (&&) executes before OR (||).
我还稍微调整了格式,使其更易于阅读。 (分隔成一个过滤器变量)