Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda