如何让机器人检测频道上每条消息的反应?
How to make the bot detects for a reaction on every message on a channel?
我希望机器人始终检测执行代码的反应(这里我试图通过反应创建一个通道)。
我尝试使用 Reaction Collector,但它有一个计时器,不能用于每条消息。
我需要一个例子,我真的尝试了很多东西,但我没有在文档上找到任何有用的东西。
I tried to use Reaction Collector but it has a timer...
对于这种误解,我深表歉意;我之前暗示收藏家是有时间限制的,我错了。
根据文档,省略 time
选项默认为无时间限制(参见 CollectorOptions
)。因此,这个例子应该继续寻找用户的反应,直到机器人停止。
message.channel.send('React with .')
.then(m => {
const filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '';
const collector = m.createReactionCollector(filter, { max: 1 });
collector.on('collect', () => {
message.clearReactions();
message.edit('You did it!');
});
})
.catch(console.error);
但是,如前所述,如果机器人停止,收集器也会停止。没有简单的方法解决这个问题。如果你真的想要无限 collection,我看到的唯一解决方案是在数据库(或 json 文件)中存储消息列表和相应的收集器,然后将它们再次应用于客户端 [=] 中的现有消息13=]事件。
我希望机器人始终检测执行代码的反应(这里我试图通过反应创建一个通道)。
我尝试使用 Reaction Collector,但它有一个计时器,不能用于每条消息。
我需要一个例子,我真的尝试了很多东西,但我没有在文档上找到任何有用的东西。
I tried to use Reaction Collector but it has a timer...
对于这种误解,我深表歉意;我之前暗示收藏家是有时间限制的,我错了。
根据文档,省略 time
选项默认为无时间限制(参见 CollectorOptions
)。因此,这个例子应该继续寻找用户的反应,直到机器人停止。
message.channel.send('React with .')
.then(m => {
const filter = (reaction, user) => user.id === message.author.id && reaction.emoji.name === '';
const collector = m.createReactionCollector(filter, { max: 1 });
collector.on('collect', () => {
message.clearReactions();
message.edit('You did it!');
});
})
.catch(console.error);
但是,如前所述,如果机器人停止,收集器也会停止。没有简单的方法解决这个问题。如果你真的想要无限 collection,我看到的唯一解决方案是在数据库(或 json 文件)中存储消息列表和相应的收集器,然后将它们再次应用于客户端 [=] 中的现有消息13=]事件。