簡體   English   中英

Discord.js bot 不會執行 .then

[英]Discord.js bot will not perform .then

我正在嘗試創建一條反應消息,但是每當我嘗試在 .then 中使用 console.log 時,它只會在消息被刪除后執行它。

async execute(message) {
    const role = message.guild.roles.cache.find(r => r.name == 'Founder');
    if (!role) return message.channel.send(`**${message.author.username}**, role not found`);

    await message.delete();

    const filter = (reaction) => reaction.emoji.name === '✅';

    const ReactionMessage = await message.channel.send('React to this message to get the Founder role');

    ReactionMessage.react('✅');

    ReactionMessage.awaitReactions(filter, { max: 10, time: 15000 })
        .then(collected => console.log(collected.size))
        .catch(err => console.error(err));
}

我的最終目標是讓它為所有對它做出反應的用戶添加一個角色,但在我刪除消息之前,它甚至不會 console.log 收集的大小。 任何人都可以幫助我完成這項工作?

awaitMessages() 只會在消息被刪除或時間用完后解析。 您可以做的是創建一個 reactCollector 並等待收集事件。

以下是一些資源: https : //discordjs.guide/popular-topics/collectors.html#reaction-collectors、https : //discord.js.org/#/docs/main/stable/class/Message ?scrollTo=createReactionCollector

嘗試更換console.log(collected.size)console.log(collected) ,看看它是如何工作的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM