最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论