Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.js - Get Message from Interaction

client.ws.on('INTERACTION_CREATE', async (interaction) => {}

The interaction class has lots of properties like channel, member and id but it doesn't have a message property.

Is there a way to get the message from an interaction or will I have to use a event listener on message? And if so, how would I use this with slash commands?

like image 395
Beatriz Mantoani Avatar asked Jan 18 '26 21:01

Beatriz Mantoani


1 Answers

You can get the user input by just using the base class interaction. However, the content is not visible, but you can view it by passing it through an api endpoint or something similar, its kind of weird for me but i'm sure there is an explanation for that.

The best way is to use interaction.options, so you'll need to add at least one option in your application command.

For example

// /test as your Application command 
client.on('interactionCreate', async interaction => {
    if (interaction.commandName === 'test') {
          const message = interaction.options.data
          console.log(message)
    })
}
like image 129
Amia Avatar answered Jan 21 '26 12:01

Amia