如何等待来自DM的消息?

时间:2019-04-22 20:09:10

标签: discord.js

如何等待私人消息中来自成员的消息?

我尝试了这个,但是没有用

client.on('message', async message => {
    if(message.content === prefix + "apply"){

      await message.author.send("Working !");
      await message.channel.awaitMessages(Response => message.content, {
        max: 1,
        time: 50000
      })
      .then((collected) => {
        if(collected.first().content === "cancel") return message.reply("Canceled");
        message.author.send("Done !");
      })
      .catch(() => {
        message.author.send("Timeout");
      })
    }
});

1 个答案:

答案 0 :(得分:0)

message.channel仍然是运行Apply的渠道,因此请使用:

const msg = await message.author.send('Working !');
const filter = collected => collected.author.id === message.author.id;
const collected = await msg.channel.awaitMessages(filter, {
    max: 1,
    time: 50000,
}).catch(() => {
    message.author.send('Timeout');
});

if(collected.first().content === 'cancel') return message.reply('Canceled');
message.author.send('Done !');