繁体   English   中英

我如何让我的不和谐机器人不从一个人那里获得多张选票

[英]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请求之外。 (我假设这是服务器代码,我对不和谐的机器人如何工作不熟悉),可能不值得将其存储在数据库中。

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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM