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

时间:2017-09-24 19:54:32

标签: javascript

我的discord.js机器人出了问题,我有一个民意调查命令,但我希望看到用户要求的一定时间后有多少反应,然后说(有)更喜欢x的人比喜欢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(`⛔`);
};

1 个答案:

答案 0 :(得分:0)

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`));

我在自己的机器人上试过这个,它做的是>首先,我使用的前缀只是ai,这就是我发送message.content但切片2的原因。我在Discord.js documentation的帮助下创建了一个反应收集器。 15秒后,它将控制.log对与表情符号reacted反应的人数。只需查看我的代码,您就可以根据自己的喜好进行调整。如果你不理解或者你想让我进一步解释,或者我做错了什么"然后回复我。