【发布时间】:2020-03-29 09:26:24
【问题描述】:
我正在尝试为我朋友的一个服务器编写一个不和谐机器人。他希望禁止命令成为多数投票的事情,如果用户试图禁止另一个用户,机器人会添加对消息的反应,当时间限制到时,机器人会根据是否有用户决定禁止用户5 票赞成。否则,禁令不会通过。
但是,我的问题是,一个用户可能会反复对勾号表情做出反应,这增加了越来越多的赞成票。我正在寻找一种方法,我可以查看用户是否已经投票,如果他们已经投票,则让他们的其他投票不计入分数。
我的代码如下所示:
const user = msg.mentions.users.first();
if(!user) return msg.reply("You need to @ someone you want me to ban");
await msg.react('✅');
await msg.react('❌');
const filter = (reaction, user) => reaction.emoji.name === '✅' && msg.author.id;
const collector = msg.createReactionCollector(filter, { time: 15000 });
let yesvotes = 0
collector.on('collect', collected => {
console.log(`Collected ${collected.emoji.name}`)
yesvotes += 1;
});
collector.on('end', collected => {
msg.channel.send(`Collected ${yesvotes} votes`)
if(yesvotes >= 5) {
// ban the user
}
});```
【问题讨论】:
标签: javascript discord discord.js