Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
How to set Discord.js v13 slash commands permissions?

I'm following the Discord.js guide to create slash commands for my bot, but I'm stuck at this point here:
https://discordjs.guide/interactions/slash-command-permissions.html#user-permissions

There are two things I can't figure out:

  • where I'm supposed to write this block of code I linked above,
  • how I'm supposed to find each command's ID

I'm creating my commands using the SlashCommandBuilder and a deploy-commands.js script as described here:
https://discordjs.guide/creating-your-bot/creating-commands.html#command-deployment-script
and here:
https://discordjs.guide/interactions/registering-slash-commands.html#guild-commands

If you can help me on either one of these two things, that would be great!
Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I've looked into the codes of the @discordjs/builders and @discordjs/rest and there is no way to set custom permissions with these packages. What you can do is create the slash commands with the Discord.js package. By creating them in the Discord.js package the id of the slash command will be returned in the fullfilled Promise. With this id you can set the permissions for the command. The only problem by doing it in this way is that it can take a while before the slash commands are working again. Here is an example:

const { Client } = require('discord.js');

const client = new Client({intents: ['Your Intents here']});

client.once('ready', () => {
   client.application.commands.create({
      name: 'your_command',
      description: "Your command's description"
   }).then(id => {
      client.application.commands.set({command: id, permissions: [
           id: 'some_user_id',
           type: 'USER',
           permission: false // Can not use the slash command
      ]}).catch(console.log);
   });
});

client.login('Your token here');

I thought that there is another way to do it, but I'm not pretty sure. If I'm right you can also fetch all the commands after you've refreshed them with the @discordjs/builders and @discordjs/rest packages. Once you've fetched them the Promise will return a Collection once it's got fullfilled. In the Collection will be all the ids of all the slash commands which you can use to set the permissions. So if this theory works, this will be the example:

const { Client } = require('discord.js');

const client = new Client({intents: ['Your Intents here']});

client.once('ready', () => {
    // Your refresh code here
    client.application.commands.fetch().then(collection => {
        collection.forEach(command => {
            if(command.name === `The specified command name`){
                 client.application.commands.permissions.set({command: command.id, permissions: [
                     {
                         id: 'some_user_id',
                         type: 'USER',
                         permission: false // Can not use the slash command
                     }
                 ]}).catch(console.log);
            }
        });
    }).catch(console.log);
});

client.login('Your token here');
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda