【问题标题】:Discord.js await messages from users other than the authorDiscord.js 等待来自作者以外的用户的消息
【发布时间】:2021-07-18 11:16:02
【问题描述】:

标题基本上说明了一切,有没有办法让我等待来自作者以外的用户的消息。比如如果用户在命令中@s 某人,我可以等待@ed 人回答某个问题吗?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您可以使用TextChannel#awaitMessages() 收听频道中的新消息。这个函数的第一个参数是一个过滤方法,它看起来像这样:

    const filter = (message) => message.content === 'COWS';
    
    message.channel.awaitMessages(filter, { max: 1 }).then((collected) => {
      // someone just said COWS in the channel
    });
    

    就像我比较消息内容一样,您也可以比较消息作者。通过这种方式,您可以听取特定人员对问题的回答,收集他们的意见,然后对其进行处理。

    【讨论】:

    • 这行得通,但是有没有办法将它指定给某个用户?
    • "就像我比较消息内容一样,你也可以比较消息作者。这样你可以听一个特定的人回答一个问题,收集他们的输入,然后用它做一些事情。”
    【解决方案2】:

    基本上只需设置过滤器,以便检查发送消息的用户是否是被 ping/提及的​​成员。

    例如

    //just get a user from the message
    let mentionedMember = message.mentions.users.first(); 
    //checks if the user who send the message is the mentioned member
    const filter = (message) => message.author == mentionedMember;
    
    message.channel.awaitMessages(filter, { max: 1 }).then((collected) => {
        //Whatever the mentioned member sent
    });
    

    【讨论】:

      猜你喜欢
      • 2020-07-02
      • 1970-01-01
      • 2021-03-29
      • 2022-06-16
      • 2019-07-10
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      相关资源
      最近更新 更多