Как я могу заставить своего бота раздора не брать несколько голосов от одного человека

1

Я создаю бот-диссонанс, у которого есть функция пропуска для музыки, но я не могу понять, как заставить кого-то не голосовать, чтобы пропустить несколько раз. До сих пор здесь мой код:

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;

Если бы вы, ребята, могли мне помочь, было бы здорово

Теги:
vote

1 ответ

2
Лучший ответ

Храните идентификатор людей, которые уже голосовали в массиве. Для каждого голосования проверьте, существует ли этот идентификатор в массиве, если это так, игнорируйте голосование.

Вам нужно объявить массив в области, которая будет сохраняться за пределами 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;

Ещё вопросы

Сообщество Overcoder
Наверх
Меню