Only permit a certain user to use a slash command

Hello! I'm currently developing my first discord bot and have a slash command which I use in dev to create my db with all the tables and relations. Instead of just deleting the slash command or excluding it from my command deployment logic when going live, I want to know, if I can just set the permission in a way only me can use it and only on my guild. Here is the command:
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
data: new SlashCommandBuilder()
.setName('db')
.setDescription('Db operations.')
.addSubcommand(subcommand =>
subcommand
.setName('create')
.setDescription('Creates a new database with all tables.')),
async execute(interaction) {
try {
const subcommand = interaction.options.getSubcommand();

switch(subcommand) {
case 'create':
//Here is my db operation to create the db
break;
}
}
catch (error) {
console.error('Error while executing db operation:', error);
await interaction.reply('There was an error executing the db operation.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');

module.exports = {
data: new SlashCommandBuilder()
.setName('db')
.setDescription('Db operations.')
.addSubcommand(subcommand =>
subcommand
.setName('create')
.setDescription('Creates a new database with all tables.')),
async execute(interaction) {
try {
const subcommand = interaction.options.getSubcommand();

switch(subcommand) {
case 'create':
//Here is my db operation to create the db
break;
}
}
catch (error) {
console.error('Error while executing db operation:', error);
await interaction.reply('There was an error executing the db operation.');
}
},
};
2 Replies
d.js toolkit
d.js toolkit10mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Vischi
VischiOP10mo ago
Ah I see. I guess that's the most common way? Thank you very much! :)
Want results from more Discord servers?
Add your server