投票在 Discord.js 中重新滚动消息
Posted
技术标签:
【中文标题】投票在 Discord.js 中重新滚动消息【英文标题】:Voting to reroll a message in Discord.js 【发布时间】:2020-12-04 23:00:45 【问题描述】:我对编程和 discord.js 很陌生,所以我使用了指南中的命令处理程序。我正在尝试创建一个机器人,当您执行 !spin 时,它会为您提供我制作的 gameList
数组中的游戏。这会按预期工作并以丰富的嵌入方式发送出去。
我想做到这一点,所以如果小组对那个游戏不满意,他们可以以至少 3 票的票数重新滚动它。为此,我尝试使用对消息的反应,但无法让任何东西真正发挥作用.
module.exports =
name: 'spin',
description: 'Spins the wheel!',
execute(message)
const gameList = ['Games inside array'];
var x = Math.floor(Math.random() * gameList.length);
var games = gameList[x];
const voteEmbed = new Discord.MessageEmbed()
.setColor('#F8AA2A')
.setTitle('????Game Spinner????')
.addField(games, ' was the chosen game!');
message.channel.send(voteEmbed).then((voteEmbed) =>
voteEmbed.react('????');
);
var noCount = 0;
const filter = (reaction, user) =>
return [`????`].includes(reaction.emoji.name);
;
const collector = message.createReactionCollector(filter, time: 10000 );
collector.on('collect', (reaction, reactionCollector) =>
if (reaction.emoji.name === `????`)
noCount += 1;
);
collector.on('end', (reaction, reactionCollector) =>
if (noCount >= 3)
message.channel.send(voteEmbed).then((voteEmbed) =>
voteEmbed.react('????');
);
);
,
;
没有错误出现,它只是在三票被击中后从不发送新的voteEmbed
。对不起,如果这是一个愚蠢的问题。
【问题讨论】:
【参考方案1】:您的错误位于此处:const collector = message.createReactionCollector(filter, time: 10000);
当您想收听对发送的消息的反应时,您正在对最终收到的消息创建一个反应收集器。
您需要将代码替换为:
主要的编辑是改变reactionCollector来收听voteEmbed消息^
const Discord = require('discord.js');
module.exports =
name: "spin",
description: "Spins the wheel!",
execute(message)
const gameList = [Games inside array]
var x = Math.floor(Math.random() * gameList.length);
var games = gameList[x];
const voteEmbed = new Discord.MessageEmbed()
.setColor("#F8AA2A")
.setTitle("?Game Spinner?")
.addField(games, " was the chosen game!");
message.channel.send(voteEmbed).then(voteEmbed =>
voteEmbed.react('?')
var noCount = 0;
const filter = (reaction, user) =>
return [`?`].includes(reaction.emoji.name);
const collector = voteEmbed.createReactionCollector(filter, time: 10000);
collector.on('collect', (reaction, reactionCollector) =>
if (reaction.emoji.name === `?`)
noCount+=1
);
collector.on('end', (reaction, reactionCollector) =>
if (noCount >= 3)
message.channel.send(voteEmbed).then(voteEmbed =>
voteEmbed.react('?')
)
);
)
;
;
【讨论】:
感谢您的回复!我尝试了上面给出的代码,但仍然没有收到任何错误,但是在达到所需的票数后,它不会重新发送新的 voteEmbed。如果您对为什么它不起作用有任何想法,我会全力以赴。以上是关于投票在 Discord.js 中重新滚动消息的主要内容,如果未能解决你的问题,请参考以下文章