[英]I want to list the users who have reacted to Discord. for Discord.js
I want to list the users who have reacted to Discord.我想列出对 Discord 做出反应的用户。
let MyChannel = client.channels.get('573534660852711426');
MyChannel.fetchMessage('656352072806957066').then(themessage => {
for (const reaction of themessage.reactions){
for (let user of reaction.users){
console.log(user);
}
console.log(reaction);
}
});
This is my code, but it doesn't work.这是我的代码,但它不起作用。 Can you help me.你能帮助我吗。
Thank you.谢谢你。
You need to use Reaction.fetchUsers
.您需要使用Reaction.fetchUsers
。 Try something like that:尝试这样的事情:
let MyChannel = client.channels.get('573534660852711426');
MyChannel.fetchMessage('656352072806957066').then(async themessage => {
for (const reaction of themessage.reactions){
for (let user of await reaction.fetchUsers(){
console.log(user);
}
console.log(reaction);
}
});
I edited reaction.users
with await reaction.fetchUsers()
and I added async
because await
must be used in an asynchronous function.我编辑reaction.users
与await reaction.fetchUsers()
和我加入async
因为await
必须在异步函数一起使用。
The error I get when I run the code is as follows.我运行代码时得到的错误如下。
at F:\js\index.js:41:37
at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:23364) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:23364) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
38 let MyChannel = bot.channels.get('648985076817985556');
39 MyChannel.fetchMessage('650431271436156969').then(async themessage => {
40 for (const reaction of themessage.reactions){
41 for (let user of await reaction.fetchUsers()){
42 console.log(user);
43 }
44 console.log(reaction);
45 }
46 });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.