我想列出对Disord有反应的用户。对于Discord.js

时间:2019-12-17 16:28:58

标签: javascript discord discord.js

我想列出对Disord有反应的用户。

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);
    }
});

这是我的代码,但是不起作用。你能帮我吗?

谢谢。

2 个答案:

答案 0 :(得分:0)

您需要使用Reaction.fetchUsers。尝试类似的事情:

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);
    }
});

我用reaction.users编辑了await reaction.fetchUsers(),并添加了async,因为await必须在异步函数中使用。

答案 1 :(得分:0)

运行代码时出现的错误如下。

    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      });