These are some simple examples for using Slash Commands in discord.js.
discord.js doesn't have full support for slash commands yet (there's a wip pr) but you can still use the underlying api and websocket to use them.
Note that discord.js doesn't officially support using client.api, this is basically just a workaround until they fully release support.
Please read Discord's Slash Command docs since they have actual docs and details for slash commands; the code examples below are just how you can implement it using discord.js.
client.ws.on("INTERACTION_CREATE", async interaction => {
// interaction is an Interaction object https://discord.dev/interactions/slash-commands#interaction
})// global commands take up to an hour to deploy
// if your application id and bot id are different, change client.user.id to the application id
client.api.applications(client.user.id).commands.post({data: {
name: 'ping',
description: 'ping pong!'
}})registering a guild command:
// guild commands deploy immediately - use these for testing
// if your application id and bot id are different, change client.user.id to the application id
client.api.applications(client.user.id).guilds('guild id').commands.post({data: {
name: 'ping',
description: 'ping pong!'
}})client.api.interactions(interaction.id, interaction.token).callback.post({data: {
type: 4,
data: {
content: 'hello world!'
}
}
})
We all know that, it's written on top of the gist and I have the repo on follow
I just wanna know what I did wrong for informational purposes, I'm already using djs master