我希望discord.js bot在命令被执行时发送一条消息,并对其做出反应,然后捕捉用户的所有反应来做某些事情,比如响应他们。反应不应受时间限制。我还应该提到,我正在使用一个命令处理程序,并且消息是从index.js以外的另一个文件发送的(在该文件中甚至应该发生collect)。
我尝试做一个收集器,但是无论我怎么做,收集器变量都没有定义或者不能工作。我知道它应该是一个事实收集器。
为勾选表情符号制作筛选器:
return reaction.emoji.name === `✅` && user.id === call.message.author.id;
}
试图捕获命令块本身之外的反应(因为如果我在该块中执行此操作,则事件将不起作用:
collector.on(`collect`, (reaction, reactionCollector) => {
console.log(`Caught ${reaction.emoji.name}`);
});
我得到的错误是预期中的,但我想解决这个问题:
collector.on(`collect`, (reaction, reactionCollector) => {
^
ReferenceError: collector is not defined
可能是一个全局变量,或者设置消息id然后获取?帮帮我。
为什么不在command.js中包含收集器呢?
const time = 60000 //amount of time to collect for in milliseconds
receivedMessage.channel.send("Hello World")
.then(async function (message) {
await message.react('✅')
const filter = (reaction, user) => {
return //YOUR FILTER HERE;
};
const collector = message.createReactionCollector(filter, { time: time });
collector.on('collect', (reaction, reactionCollector) => {
//do stuff
});
});