简体   繁体   English

Discord.js结果轮询命令需要一些工作

[英]Discord.js result poll command that needs some work

I am having a problem with my discord.js bot, where I have a poll command, 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机器人出现问题,我有一个轮询命令,但我希望它查看用户要求的一定时间后它有多少反应,然后说(有更多的人比喜欢y的人更喜欢x)。

discord.js: 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(`⛔`);
};
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 . 我在自己的机器人上尝试了此操作,然后做了>首先,我使用的前缀只是ai,这就是为什么我只发送message.content但切成薄片2的原因。我借助Discord.js文档制作了一个反应收集器。 After 15 seconds it will console.log the amount of people who have reacted with the emoji ✅. 15秒钟后,它将控制台。记录与表情符号oji反应的人数。 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. 如果您不理解或希望我进一步解释,或者“我做错了”,请回复给我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM