消息采集器回复别人的消息

Message collector responds to other people's messages

我正在尝试制作一个收集器来收集提到的用户的消息。但即使使用过滤器,我的机器人也会响应它自己的消息和其他人的消息!这是我的 test.js 文件代码:

const mentioned = message.mentions.users.first();

const filter1 = (msg) => {
  return msg.author.id === mentioned.id
}

const collector1 = await message.channel.createMessageCollector({ filter1, max: 1, time: 120000 })

collector1.on('collect', message => {
  console.log(message.content)
})

collector1.on('end', (collected) => {
  if (collected.size === 0) return message.channel.send("Mentioned user did not respond in time!")

  collected.forEach((message) => {
    if (message.content.toLowerCase() == 'accept') {
      message.channel.send(`${mentioned} accepted!`)
    }
    if (message.content.toLowerCase() == 'cancel') return message.channel.send(`${mentioned} declined!`)
  })
})

我更换了很多次过滤器,但我仍然无法解决这个问题,所以我做错了什么? 我也使用 djs v13

问题是您正在尝试使用 Short-Hand Property Assignment to assign the filter option. However, you pass in "filter1" which results in {filter1: filter1}. Since this does not resolve to a filter option for TextChannel#createMessageCollector() 该方法忽略了未知选项,因此您的收集器没有过滤器。

将您的 filter1 变量更改为 filter

const filter = (msg) => {
  return msg.author.id === mentioned.id
}

const collector1 = await message.channel.createMessageCollector({ filter, max: 1, time: 120000 })