javascript - Discord.js result poll command that needs some work - Stack Overflow

I am having a problem with my discord.js bot, where I have a poll mand, but I want it to see how many r

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
Add a ment  | 

1 Answer 1

Reset to default 3
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(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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信