Recently, discord added support for slash commands for your own application. I read through the documentation for it, and I've tried to search for some videos (however the feature did JUST come out) but I do not understand what I actually have to do to get it working. I am using WebStorm (js, node.js). Has anyone successfully made a slash command, and if so, how?
Documentation
If your app has no slash commands, that means your developer hasn't migrated to them yet. You can visit their support server or contact them to let them know - they might be juggling a lot, life can get busy!
discord. js doesn't have full support for slash commands yet (there's a pr) but you can still use the underlying api and websocket to use them. Note that discord. js doesn't officially support using client.
You can use the regular discord.js
, by now its v12.5.1
.
This is just a sample, but worked for me.
const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { client.api.applications(client.user.id).guilds(YOUR_GUILD_ID_HERE).commands.post({ data: { name: "hello", description: "hello world command" // possible options here e.g. options: [{...}] } }); client.ws.on('INTERACTION_CREATE', async interaction => { const command = interaction.data.name.toLowerCase(); const args = interaction.data.options; if (command === 'hello'){ // here you could do anything. in this sample // i reply with an api interaction client.api.interactions(interaction.id, interaction.token).callback.post({ data: { type: 4, data: { content: "hello world!!!" } } }) } }); }); client.login(token);
Of course you can have options, see documentation...
IDE won't register the new code...at least my php storm currently does'nt :)
However, its important to give the bot the correct permissions to use this type of command!
So go to Discord.com/developers, select your application, go to OAuth2
and select
application.commands
from the scope section. This should be at the bottom of the middle column. You should select bot
as well and under Bot Permissions
you set some other specific permissions. Then use that new invite link to reinvite the bot.
Without application.commands
permission, the command won't work and you will receive some error like Missing Access
or some similar.
IMPORTANT THINGS
Use .guilds('11231...').comma
to test these commands. When not using this, it takes round about 1h to get active. Using it will activate it immediately.
Give the bot the correct permission. application.commands
Hi I don't usually work with discord.js but I was able to find some good documentation on this. You should be able to do it like this with "client" defined.
const interactions = require("discord-slash-commands-client"); const client = new interactions.Client( "you unique bot token", "your bots user id" );
If the client is defined as shown, then a /command should work if defined like this.
// will create a new command and log its data. //If a command with this name already exist will that be overwritten. client.createCommand({ name: "your command name", description: "description for this command", }) .catch(console.error) .then(console.log);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With