[英]Pick random user from message reaction
How I can pick a random user from message reaction in discord? 如何从不协调的消息响应中选择随机用户?
I've read all the documentation, but I still do not understand. 我已经阅读了所有文档,但仍然不明白。
Message.reactions
contains every reaction to the message, mapped by the id. Message.reactions
包含对消息的每个响应,由ID映射。
You just have to choose a random reaction and then choose one of the users that reacted: 您只需要选择一个随机反应,然后选择做出反应的用户之一:
if (message.reactions.size) {
let reaction = message.reactions.random(1);
let randomUser = reaction.users.random(1);
}
To choose the random reaction and the random user I used Collection.random()
. 为了选择随机反应和随机用户,我使用了
Collection.random()
。
If you don't want to choose a random reaction but you have your own, you can use this: 如果您不想选择随机反应,但是您有自己的反应,则可以使用以下方法:
if (message.reactions.size) {
let reaction = message.reactions.find(r => r.emoji.name == '😂');
if (reaction) {
let randomUser = reaction.users.random(1);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.