Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
slash command discord permission

I want to have a slash command that only admin can use but I can't find the option for this purpose

const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');

const commands = [
    
    new SlashCommandBuilder().setName('setting').setDescription('Replies with the setting!').setDefaultPermission(false)
    
    .addSubcommand(subcommand => subcommand.setName('log').setDescription('Select a user')
        .addChannelOption(option => option.setName('log-channel').setDescription('Select a channel'))
        .addStringOption(option => option.setName('delete-log').setDescription('Delete log channel'))), 
]
   .map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);

rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
    .then(() => console.log('Successfully registered application commands.'))
    .catch(console.error);

This is my slash command when I'am using this code the command is locked so this is good for when the user is not an admin enter image description here

But I want the command to be unlucked when the user as the permission admin like so

enter image description here

So I was wondering if I could set the permission for the command like this

const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');

const commands = [
    
    new SlashCommandBuilder().setName('setting').setDescription('Replies with the setting!').setDefaultPermission(false).setPermission('ADMINISTRATOR')
    
    .addSubcommand(subcommand => subcommand.setName('log').setDescription('Select a user')
        .addChannelOption(option => option.setName('log-channel').setDescription('Select a channel'))
        .addStringOption(option => option.setName('delete-log').setDescription('Delete log channel'))), 
]
   .map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);

rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
    .then(() => console.log('Successfully registered application commands.'))
    .catch(console.error);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

From the documentation,

const permissions = [
  {
      id: '464464090157416448',
      type: 'ROLE',
      permission: false,
  },
];

await command.permissions.add({ permissions });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!