[英]Get all users who have added a reaction to a message (discord.js)
In discord.js, how do I get all the users who have added a reaction to a message? discord.js,如何获取所有回复过一条消息的用户? (And then do something with their ID and tag etc.) Below is what I thought it would be but it doesn't work, and I can't find anything to help me on the inte.net with what I'm searching. (然后用他们的 ID 和标签等做一些事情)下面是我的想法,但它不起作用,我在 inte.net 上找不到任何可以帮助我搜索的东西。
var users = msg.reactions.resolve(messageID).users.cache;
var userIDs = [];
var userTags = [];
users.forEach(user => {
userIDs.push(user.id);
userTags.push(user.tag);
}
Thanks.谢谢。
Hopefully, this is enough to help you out:D希望这足以帮助您:D
Edit: This will now target a message with a specific string (aka, an old message)编辑:这现在将针对具有特定字符串的消息(又名旧消息)
var targetedMessage = "Whatever the string is of that specific old message";
var userIDs = [];
var userTags = [];
client.on("message", message => {
//Alternate targeting technique
/*if(message.content == "reactMe") {
targetedMessage = message.id;
}*/
if(message.content == "whoReacted" && targetedMessage != null) {
var theReactors = "Everyone who reacted was:";
for(var i = 0; i < userIDs.length; i++) {
theReactors = theReactors + ` <@${userIDs[i]}>`;
}
message.channel.send(theReactors);
}
}
client.on("messageReactionAdd", (reaction, user) => {
if(reaction.message.content == targetedMessage) {
var reacted = false;
for(var i = 0; i < userIDs.length; i++) {
if(user.id == userIDs[i]) {
reacted = true;
}
}
if(!reacted) {
userIDs.push(user.id);
userTags.push(user.tag);
}
}
});
This is not the nicest way to do it:这不是最好的方法:
let channel = await bot.channels.fetch(channelId)
let message = await channel.messages.fetch(messageId)
let reactions = await message.reactions.cache.first().users.fetch()
reactions = reactions.toJSON()
for(i = 0; i < reactions.length; i ++) console.log(reactions[i].id)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.