# Slash Commands in Discord.js 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](https://github.com/discordjs/discord.js/pull/5106)) 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](https://discord.com/developers/docs/interactions/slash-commands) since they have actual docs and details for slash commands; the code examples below are just how you can implement it using discord.js. Note that slash commands won't show in a server unless that server has authorized it with the `applications.commands` oauth2 scope (not just the `bot` scope). ## Registering a Command: You only need to register each command one time. You might wanna use an eval command for this. Send a [Command](https://discord.com/developers/docs/interactions/slash-commands#applicationcommand) object ### Global Commands global commands show in all authorized servers, but take up to an hour to deploy. ```js // 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!' }}) ``` ### Guild-specific commands guild commands deploy immediately - use these for testing ```js // 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!' }}) ``` ## Receiving the Event `interaction` is an [Interaction object](https://discord.com/developers/docs/interactions/slash-commands#interaction) ```js client.ws.on("INTERACTION_CREATE", async interaction => { }) ``` ## Responding To An Interaction: send an [Interaction Response](https://discord.com/developers/docs/interactions/slash-commands#interaction-interaction-response) object ```js client.api.interactions(interaction.id, interaction.token).callback.post({data: { type: 4, data: { content: 'hello world!' } } }) ``` shortlink: [s.advaith.io/slashdjs](https://s.advaith.io/slashdjs)