如何解决投票重新发布Discord.js中的消息
我一般对编程和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',reactionCollector) => {
if (noCount >= 3) {
message.channel.send(voteEmbed).then((voteEmbed) => {
voteEmbed.react('?');
});
}
});
},};
没有错误出现,只有经过三票投票,它才不会发送新的voteEmbed
。抱歉,这是一个愚蠢的问题。
解决方法
您的错误位于此处:const collector = message.createReactionCollector(filter,{time: 10000});
当您要收听对已发送消息的反应时,您将在最后收到的消息上创建一个反应收集器。
您需要使用以下代码替换代码:
主要编辑是更改responseCollector以收听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',reactionCollector) => {
if (noCount >= 3){
message.channel.send(voteEmbed).then(voteEmbed => {
voteEmbed.react('?')
})
}
});
})
};
}
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。