简体   繁体   中英

Discord.js Interaction await messages cannot get message objects

Once a user creates an interaction in a discord channel I want to listen for new incomming messages in that channel. Here is the code I got

if(interaction.customId.startsWith("TRIGGER")){
let filter = m => m.author.id === interaction.author.id
interaction.channel.send(`Are you sure to delete all data? \`YES\` / \`NO\``).then(() => {
  interaction.channel.awaitMessages(filter, {
      max: 1,
      time: 30000,
      errors: ['time']
    })
    .then(message => {
      message = message.first()
      if (message.content.toUpperCase() == 'YES' || message.content.toUpperCase() == 'Y') {
        message.channel.send(`Deleted`)
      } else if (message.content.toUpperCase() == 'NO' || message.content.toUpperCase() == 'N') {
        message.channel.send(`Terminated`)
      } else {
        message.channel.send(`Terminated: Invalid Response`)
      }
    })
    .catch(collected => {
        interaction.channel.send('Timeout');
    });
})

However I dont get the message objects. Its like no messages are send

How can I solve this issue?

Your issue most likely lies in your filter as no interaction has an author property. Consider changing your filter to the following:

let filter = m => m.author.id === interaction.user.id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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