我制作了一个机器人,如果您输入命令,它将发送一条消息,如果您对该消息做出反应,它将发送另一条消息,但如果我再次运行该命令并对第一条消息做出反应,它将发送该消息两次我该如何解决?
client.on('messageReactionAdd', async (reaction, user)=>{
if(user.bot) return;
if (reaction.emoji.name === '⛔') {
clearInterval(my_interval);
clearTimeout(my_timeout);
const exampleEmbed1 = new Discord.MessageEmbed()
.setColor('#fefefe')
.setTitle(`Your record was ${index}s!`)
.setAuthor(message.author.tag, message.author.avatarURL())
.setDescription('Bot made by tempacc')
if(run){
message.channel.send(exampleEmbed1);
index = 0;
message.member.voice.channel.leave();
run = false;
}else if(!run){
message.channel.send('You must start a speedrun before running this command!');
}
}
})
答案 0 :(得分:1)
我建议您改用反应收集器,但我会在此处提供一个示例以及文档,供其他人使用。
const filter = (reaction, user) => {
return reaction.emoji.name === '?'; // Check reaction was a ? and not anything else
};
const collector = message.createReactionCollector(filter, { time: 15000 });
collector.on('collect', (reaction, user) => {
console.log(`Collected ${reaction.emoji.name} from ${user.tag}`);
});
collector.on('end', collected => {
console.log(`Collected ${collected.size} items`);
});
无论 time
在哪里,您也可以将 max
、maxUsers
或 maxEmojis
传递到此数据对象中,例如:
const collector = message.createReactionCollector(filter, { maxUsers: 1 });