计算经过一定时间后对消息的反应



所以我制作了一个有投票命令的机器人,你让它说一句可投票的话,人们只能在discord.js 中用tick、cross或N/a做出反应

我现在需要做的是一个响应(通过命令或随着时间的推移自动进行,但最好在24小时内自动进行(。

到目前为止,我已经尝试了许多不同的方法,并查看了所有Discord.js文档,但都没有完全成功。以下是代码的结果,尽管它不起作用:

var textToEcho = args.join(" ");
Client.channels.cache.get('channel ID').send(textToEcho).then(async m => {
await m.react('✅');
await m.react('❎');
await m.react('801426534341541919');
});
message.channel.fetchMessage(textToEcho).then(msg => {
let downVoteCollection = msg.reactions.filter(rx => rx.emoji.name == '✅');
console.log(downVoteCollection.first().count);
}).catch(console.error);

注意:此检查勾号响应。

似乎您正试图在消息发送后直接获取所有反应,这只会返回机器人的反应(如果有的话(
要准确地获得一段时间后的反应,您必须添加.setTimeout(...)函数。

var textToEcho = args.join(" ");
Client.channels.cache.get('channel ID').send(textToEcho).then(async m => {
await m.react('✅');
await m.react('❎');
await m.react('801426534341541919');
});
setTimeout(() => {
message.channel.messages.fetch(message.id).then(msg => {
let downVoteCollection = msg.reactions.filter(rx => rx.emoji.name == '✅'); // Filter the reactions
msg.author.send(`You have received **${downVoteCollection.first().count}** votes on your latest poll!`); // Sends the poll owner how many votes they recieved
}).catch(console.error);
}, 86400000); // This will wait 24 hours after the message has been sent to count reactions

最新更新