Discord.js Bot赠品命令:.array()不是函数

时间:2020-07-16 12:30:30

标签: javascript arrays discord bots discord.js

我正在尝试发出Discord.js赠品命令来发送嵌入,将其保存到变量embedSent,在TimeOut之后使用reacts.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。

1 个答案:

答案 0 :(得分:1)

user.fetch()返回一个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);