'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

But I want the command to be unlucked when the user as the permission admin like so
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);
Solution 1:[1]
From the documentation,
const permissions = [ { id: '464464090157416448', type: 'ROLE', permission: false, }, ]; await command.permissions.add({ permissions });
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kureteiyu |

