我怎样才能让我的不和谐机器人不从一个人那里获得多票

How can I get my discord bot not to take multiple votes from a single person

我正在制作一个具有音乐跳过功能的 discord 机器人,但我不知道如何让某人无法多次投票跳过。到目前为止,这是我的代码:

case "skip":
        var server = servers[message.guild.id];
        if(message.guild.members.get(message.author.id).roles.exists('name','Super Skip')){ // checks if the member has the super skip role
            skipvotes = 0; // sets skipvotes back to 0
            messagesend("Skipping Song")
            server.dispatcher.end(); // skips song
            message.delete(); // deletes message that sent the commmand
            return;
        }
        skipvotes++ // increases the skipvotes
        if(skipvotes != 5) { // checks if the number of skips is 5 or not
            message.delete();
            messagesend(5-skipvotes + " more vote(s) to skip the song") // sends the message saying how many more votes to skip the song
        } else if(skipvotes === 5){
            skipvotes = 0; // sets the number of skipvotes back to 0
            if(server.dispatcher){
                message.delete();
                messagesend("Skipping song")
                server.dispatcher.end(); // skips the song
            }
        }
        break;

如果你们能帮助我,那就太好了

将已经投票的人的 ID 存储在一个数组中。对于每次投票,检查该 id 是否已存在于数组中,如果存在,则忽略该投票。

您需要在将在 http 请求之外持续存在的范围内声明数组。 (我假设这是服务器代码,我不熟悉 discord 机器人的工作原理)可能不值得将其存储在数据库中。

var voters = []

用数组的长度替换整数计数器。

case "skip":
        var server = servers[message.guild.id];
        if(message.guild.members.get(message.author.id).roles.exists('name','Super Skip')){ // checks if the member has the super skip role
            voters = []
            messagesend("Skipping Song")
            server.dispatcher.end(); // skips song
            message.delete(); // deletes message that sent the commmand
            return;
        }

        if(voters.find(id=>id == message.author.id))
            return;

        voters.push(message.author.id)

        if(voters.length != 5) { // checks if the number of skips is 5 or not
            message.delete();
            messagesend(5-voters.length + " more vote(s) to skip the song") // sends the message saying how many more votes to skip the song
        } else if(voters.length === 5){
            voters = []
            if(server.dispatcher){
                message.delete();
                messagesend("Skipping song")
                server.dispatcher.end(); // skips the song
            }
        }
        break;