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?
Slash commands have their own type of message. I don't believe they have an id, delete button, edit button or lots of things most messages do. This means you will not be able to get the "message" from a slash command. From buttons however, they do emit INTERACTION_CREATE
but has a little more info. I don't remember for sure, but I think you can use something like interaction.components
. I am not completely sure, but if you want, click a button and log the interaction into your console to see the unique button info like this
client.ws.on('INTERACTION_CREATE', async (interaction) => {
{
console.log(interaction) //will be long!
//…
})
You can get the user input by just using the base class interaction
. However the content is not visible. You can access it by passing it through an api endpoint or something similar.
For example
client.on('interactionCreate', async interaction => {
if (interaction.commandName == 'greet') {
fetch(base_url + `api/greet?msg=${interaction}`) // the server can read the user input here
.then(res => res.json())
.then(async data => {await interaction.reply(data.content)}) // send back the data
}
})
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.