discord.js-等待消息并检查dm消息

时间:2020-11-07 15:27:43

标签: discord.js

我什么都没做,我一直在浏览整个互联网,没有任何帮助 请帮助我的代码如下。 我正在将discord.js与node.js 14.15.0一起使用, 此代码不在main.js文件内,因此不作为客户端。不会工作, 即时通讯使用命令集

im试图检查用户何时响应其dm中的消息

if(message.channel.type === 'dm'){
    message.channel.awaitMessages(message.author.id, {max: 1, time: 30000}).then(collected => {
         console.log(message.author);
         if(collected.first().content.toLowerCase() == 'cancel'){
              message.author.send('canceled');
         }
    }).catch(err =>{
         message.author.send('took too long canceling');
    });
 };

1 个答案:

答案 0 :(得分:0)

在DM频道message.author.send中等待消息无效。
由于这些DM仍在频道message.channel.send中,因此可以正常工作。
示例代码:

client.on('message', message => { //Adding the event listener
    if(message.channel.type === 'dm') { //If the message was via direct message
        message.channel.awaitMessages(message.author.id, { max: 1, time: 30000 }).then(collected => { //awaiting the next message
            if (collected.first().content.toLowerCase() === 'cancel') { //if the awaited message is equal to 'cancel'
                message.channel.send('Canceled prompt.'); //let the user know that their erequest has been canceled
            }
        }).catch {
            message.channel.send('Timeout proceeded, canceling.'); //if the user has ran out of time, let them know
        };
    }
});