我正在开发这个机器人程序,我希望用户只能在表情符号中做出一次反应,如果他在其他时候做出反应,该命令将无效。有人能帮我吗?
let messagereturn = await message.channel.send(embed);
await messagereturn.react('🔁');
const reactions = ['🔁'];
const filter = (reaction, user) => reactions.includes(reaction.emoji.name) && user.id === User.id;
const collector = messagereturn.createReactionCollector(filter)
collector.on('collect', async emoji => {
switch(emoji._emoji.name) {
case('🔁'):
const embed1 = new Discord.MessageEmbed()
.setColor('#00ff00')
.setDescription(`${User} **deu um tapa em** ${message.author}`)
.setImage(rand)
await message.channel.send(embed1)
}
})
createReactionCollector
方法有一个可选的options
对象,它允许您设置要收集的最大反应,在您的情况下为1。
示例:
const collector = messagereturn.createReactionCollector(filter, { max: 1 })