I am having a problem with my discord.js bot, where I have a poll mand, but I want it to see how many reactions it has after a certain amount of time that the user asks for, then say (There are more people who prefer x than people who prefer y).
discord.js:
const Discord = require('discord.js')
exports.run = async (bot, message, args) => {
if (!args) return message.reply("You must have something to vote for!")
if (!message.content.includes("?")) return message.reply("Include a ? in your vote!")
message.channel.send(`:ballot_box: ${message.author.username} started a vote! React to my next message to vote on it. :ballot_box: `);
const pollTopic = await message.channel.send(`${args}`);
pollTopic.react(`✅`);
pollTopic.react(`⛔`);
};
I am having a problem with my discord.js bot, where I have a poll mand, but I want it to see how many reactions it has after a certain amount of time that the user asks for, then say (There are more people who prefer x than people who prefer y).
discord.js:
const Discord = require('discord.js')
exports.run = async (bot, message, args) => {
if (!args) return message.reply("You must have something to vote for!")
if (!message.content.includes("?")) return message.reply("Include a ? in your vote!")
message.channel.send(`:ballot_box: ${message.author.username} started a vote! React to my next message to vote on it. :ballot_box: `);
const pollTopic = await message.channel.send(`${args}`);
pollTopic.react(`✅`);
pollTopic.react(`⛔`);
};
Share
Improve this question
edited Sep 24, 2017 at 21:51
Alessandro Romano
7731 gold badge10 silver badges35 bronze badges
asked Sep 24, 2017 at 19:54
ThatMajesticGuyThatMajesticGuy
111 silver badge2 bronze badges
2
- What problems are you encountering? What didn't work? Please help us help you :) – Matheus Avellar Commented Sep 24, 2017 at 20:07
- Sorry about that xD, Im not having any specific answers, im just basically asking the question "How do you find out how many more reactions does ✅ have than ⛔, or vice versa – ThatMajesticGuy Commented Sep 25, 2017 at 23:37
1 Answer
Reset to default 3if (!args) return message.reply("You must have something to vote for!")
if (!message.content.includes("?")) return message.reply("Include a ? in your vote!")
message.channel.send(`:ballot_box: ${message.author.username} started a vote! React to my next message to vote on it. :ballot_box: `);
const pollTopic = await message.channel.send(message.content.slice(2));
await pollTopic.react(`✅`);
await pollTopic.react(`⛔`);
// Create a reaction collector
const filter = (reaction) => reaction.emoji.name === '✅';
const collector = pollTopic.createReactionCollector(filter, { time: 15000 });
collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
I tried this on my own bot and what it did was > Firstly the prefix i used was just ai which is why i just sent the message.content but sliced 2. I made a reaction collector with the help of the Discord.js documentation. After 15 seconds it will console.log the amount of people who have reacted with the emoji ✅. Just look at my code and you can bend it to your preferences. If you didnt understand or you want me to further explain, or "i did something wrong" then reply back to me.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745236574a4617928.html
评论列表(0条)