Probably I didn't understand quite well how Discord API works when we use awaitMessages. What I'm trying to do is to wait for a message from the user after a button was clicked in a private channel:
client.on('interactionCreate', async interaction => {
if (interaction.isButton()) {
if (interaction.customId.startsWith('dialogue-')) {
const embed = new MessageEmbed()
.setColor('#1a8175')
.setTitle(' Dialogue')
.setDescription('Please type your dialgoue')
await interaction.channel.send({embeds: [embed]})
// My problem lies here
const filter = m => m.author.id === interaction.author.id;
await interaction.channel.awaitMessages(filter, {
max: 1,
time: 60000,
errors: ['time']
}).then(
async(collected) => {
await interaction.channel.send('Received: ' + collected.first().content.toLowerCase())
})
}
}
As you can see, the user clicks on the button, a message is sent asking for the dialogue. After that the bot should receive the next message.
After debugging I saw that everything that I type after the message is sent to the user, triggers the messageCreate event, which is why my code is not working. In my understanding, when we use awaitMessages the bot should wait for the Promise to be completed. I can't figure out what I am missing here. Any ideas? Thanks in advance