0
I’m trying to make a bot for Discord. The command I’m doing does the following (It’s a voting system):
1-You quote who will be a candidate.
2-The bot sends in the same channel the people mentioned in different messages.
3-You vote reacting to someone.
4-The most voted person wins.
And it was managing to do this, the problem is in step 4. The bot should put each message with its reactions (votes) in an array. Then he takes a property that has in every reaction,
.Count -> That’s how much of the same reaction was made.
And it sorts the array according to the amount of votes (Count), and then it takes the first item of the array (which would be this message with more reactions). But it’s not working, the code is as follows:
setTimeout(() => {
//voted_colls -> É toda reação que ele coletou. Ele é um array, e cada item é uma collection de
//um objeto.
voted_colls = voted_colls.sort((a, b) => {
if (a.first().count > b.first().count){
return 1;
}
if (a.first().count < b.first().count){
return -1;
}
return 0;
});
let impostor = voted_colls[0].first().message.mentions.users.first();
}, 10550);
}
Well, in my vision I had to pick up the first item already ordered and it was all right. But he doesn’t order, I’ve tried several methods to order.
This image expresses the command (almost) ready (The only problem as already said, is that the result did not come out the most voted):
Yes, my command is an Among Beacon 9-9
Vlw! With your tip and some tweaks worked!
– Giraffa