【问题标题】:Discord.js Bot giveaway command : .array() is not a functionDiscord.js Bot 赠品命令:.array() 不是函数
【发布时间】:2020-11-06 03:00:02
【问题描述】:

我正在尝试制作一个发送嵌入的 Discord.js 赠品命令,将其保存到变量 embedSent,在 TimeOut 之后使用反应.get() 方法收集反应,使用 array() 将它们转换为数组然后用 .filter() 过滤它们。问题出在 Array() 步骤,我不断收到错误TypeError: peopleReactedBot.array is not a function。
这是我的代码的一部分:

embedSent.react("????");
setTimeout(function () {
    try {
        const peopleReactedBot = embedSent.reactions.cache.get("????").users.fetch();
        const peopleReacted = peopleReactedBot.array().filter(u => u.id !== client.author.id);
        message.channel.send(peopleReacted)
    } catch(e) {
        return message.channel.send("An error has occured : `"+e+"`");
    }
}, time);

我使用 Discord.js v12。

【问题讨论】:

    标签: javascript arrays discord bots discord.js


    【解决方案1】:

    user.fetch() 返回一个 Promise,因此您可能希望切换到异步函数并等待 Promise 完成,如下所示:

    setTimeout(async () => {
        try {
            const peopleReactedBot = await embedSent.reactions.cache.get("?").users.fetch();
            const peopleReacted = peopleReactedBot.array().filter(u => u.id !== client.author.id);
            message.channel.send(peopleReacted)
        } catch(e) {
            return message.channel.send("An error has occurred : `"+e+"`");
        }
    }, time);
    

    【讨论】:

      猜你喜欢
      • 2020-09-17
      • 2020-03-17
      • 2021-04-18
      • 2021-03-10
      • 2020-04-17
      • 2021-03-20
      • 2021-04-02
      • 1970-01-01
      • 2020-10-30
      相关资源
      最近更新 更多