简体   繁体   English

Discord.js 等待作者以外用户的消息

[英]Discord.js await messages from users other than the author

The title basically says it all, Is there a way for me to await for a message from a user other than the author.标题基本上说明了一切,有没有办法让我等待来自作者以外的用户的消息。 Like if a user @s someone in the command can I wait for the @ed person to respond to a certain question?例如,如果用户在命令中@s 某人,我可以等待@ed 人回答某个问题吗?

You can use TextChannel#awaitMessages() to listen for new messages in a channel.您可以使用TextChannel#awaitMessages()来侦听频道中的新消息。 The first parameter of this function is a filter method, which can look something like this:这个 function 的第一个参数是一个过滤方法,它可以看起来像这样:

const filter = (message) => message.content === 'COWS';

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

Just as I compared the message content, you can also compare the message author.就像我比较消息内容一样,您也可以比较消息作者。 This way you can listen for a specific person to respond to a question, collect their input, and then do something with it.通过这种方式,您可以听取特定人员对问题的回答,收集他们的意见,然后对其进行处理。

Basically just set the filter so it checks if the user who sent a message is the pinged/mentioned member.基本上只需设置过滤器,以便检查发送消息的用户是否是被 ping/提及的成员。

Ex.前任。

//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
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM