【问题标题】:Check if someone replies to a bot in discord.js检查是否有人回复了 discord.js 中的机器人
【发布时间】:2021-10-14 03:48:27
【问题描述】:

我正在制作一个不和谐的机器人来向人们提问。如何检查某个用户是否回复了它? (用户 A 会说“!询问 @UserB”,Bot 会说“@UserB,请回答问题”,用户 B 会回复。)我知道一般代码有效,但我需要一种方法来检查回复和内容他们。

代码:

module.exports = {
    name: 'ask',
    description: 'asks a question',
    async execute(message, args) {
        if (!args[0]) {
            message.reply("Specify User");
        } else {
            message.channel.send(args[0] + " Please answer the question."); // args[0] will be the user
        }
    }
}

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    所有消息都有一个message_reference 属性。这包含公会、频道和消息 ID。如果不是回复,则此属性为 null。我假设您已经知道该频道。

    //async function
    //message is an instance of Message
    let { channel, message_reference: reply } = message
    const repliedTo = await channel.messages.fetch(reply.message_id);
    //repliedTo is now the replied message with author, content, etc
    if(repliedTo.author.bot) {
    //replied messages author is a bot
    }
    

    复制自我的回答here

    【讨论】:

      猜你喜欢
      • 2021-10-13
      • 2021-01-08
      • 2021-08-18
      • 2021-04-24
      • 2017-10-31
      • 2019-04-24
      • 2020-07-02
      • 2022-06-25
      • 2021-08-09
      相关资源
      最近更新 更多