消息收集器是否可以在Discord.js中收集DM?

时间:2019-07-17 02:58:24

标签: javascript node.js discord.js

我正在尝试收集用户对我的漫游器消息的答复,但所有答复都在DM中。如何使用Discord.js(12.0.0-dev)的master分支完成此任务?

我试图用下面的代码段收集消息...

const collector = new MessageCollector(message.author.DMChannel, m => m.author.id === message.author.id, { max: 1, time: 120000 });
const collector = message.author.dmChannel.createMessageCollector({ max: 1, time: 120000 })

这似乎是我所需要的,但我只希望它返回用户发送的第一条消息。当我console.log()结果时,它始终是不确定的。

2 个答案:

答案 0 :(得分:1)

在DM通道中,您可以使用channel.createMessageCollector()中的message.channel创建收集器

client.on('message', message => {
  if (message.content == `!collect`) {
    // Create a message collector
    const filter = m => (m.content.includes('discord') && m.author.id != client.user.id);
    const channel = message.channel;
    const collector = channel.createMessageCollector(filter, { time: 10000 });
    console.log("collector started");
    collector.on('collect', m => console.log(`Collected ${m.content}`));
    collector.on('end', collected => console.log(`Collected ${collected.size} items`));
  }
});

答案 1 :(得分:0)

您可以轻松收集用户对机器人消息的回复。

使用 DM 频道, 使用

创建一个“收集器”
channel.createMessageCollector()

来自

message.channel

您的代码应该与给定的块匹配:

client.on('xyz', message => {
  if (message.content == `!collect`) {
    const filter = m => (m.content.includes('media') && m.author.id != 
    client.user.id);
    const channel_xyz = message.channel;
    const collector = channel.createMessageCollector(filter, { time: 10000 });
    console.log("collector started");
    collector.on('collected', m => console.log(`Collected ${m.content}`));
    collector.on('end', collected => console.log(`Collected ${collected.size} 
items`));
  }
 });