[英]How to make a reaction disappear after a certain amount of reactions?
我想制作一个轮询命令,在我使用该命令的地方,当反应达到一定数量的反应时,它(反应)被删除。 如果你理解我的话,这将有助于看看谁赢了。
这就是我现在用来添加反应的东西。
bot.on('message', msg => {
if(msg.content === "memes"){
msg.react("🤏🏾")
}
})
您可以使用反应收集器来收集用户对消息的反应。 收集器具有诸如maxUsers
之类的选项,您可以使用这些选项来设置要做出反应的最大用户数。 一旦到达, collector.on('end')
就会触发,因此您可以使用它来获取做出反应的用户数量等。
您可以使用message.reactions.removeAll();
检查下面的片段:
if (message.content === 'memes') {
const EMOJI = '🤏🏾';
const filter = (reaction, user) =>
reaction.emoji.name === EMOJI && !user.bot;
const collector = message.createReactionCollector(filter, {
// optional, the maximum time in ms the collector collects reactions
time: 10000,
// maximum number of users to react
// it includes the bot's reaction too
maxUsers: 3,
});
message.react(EMOJI);
collector.on('collect', (reaction, user) => {
// it fires every time someone reacts to the message
console.log('collected', reaction);
});
collector.on('end', async (collected, reason) => {
const reaction = collected.get(EMOJI);
if (!reaction) {
return message.channel.send('Oops, there were no reactions');
}
// it includes the bot too
const allUsers = await reaction.users.fetch();
// collection of users who reacted to the message, bot removed
const users = allUsers.filter((user) => user != client.user);
message.channel.send(
`Poll has ended because of ${reason}. Received ${users.size} reactions.`
);
message.channel.send(
`Users reacted: ${users.array().join(', ')}`
);
// remove reactions
message.reactions.removeAll();
});
}
如果你想要一个表情符号数组,你可以使用一个EMOJIS
数组来代替:
if (message.content === 'memes') {
const EMOJIS = ['🤏🏾', '😱'];
const filter = (reaction, user) =>
EMOJIS.includes(reaction.emoji.name) && !user.bot;
const collector = message.createReactionCollector(filter, {
time: 10000,
maxUsers: 3,
});
EMOJIS.forEach((emoji) => message.react(emoji));
collector.on('collect', (reaction, user) => {
// it fires every time someone reacts to the message
});
collector.on('end', async (collected, reason) => {
if (!collected.size) {
message.reactions.removeAll();
return message.channel.send('Oops, there were no reactions');
}
// you can use the collected reactions any way you want
console.log(collected);
// remove reactions
message.reactions.removeAll();
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.