【问题标题】:I want to list the users who have reacted to Discord. for Discord.js我想列出对 Discord 做出反应的用户。对于 Discord.js
【发布时间】:2020-04-10 04:48:30
【问题描述】:

我想列出对 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);
    }
});

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

谢谢。

【问题讨论】:

  • 当你说它不起作用时,它会给你一个错误、一个不正确的答案还是什么都没有发生?

标签: javascript discord discord.js


【解决方案1】:

我运行代码时遇到的错误如下。

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

【讨论】:

    【解决方案2】:

    您需要使用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);
        }
    });
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-23
      • 2018-04-03
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      • 2021-03-26
      相关资源
      最近更新 更多