Vischi
Vischi
DIAdiscord.js - Imagine an app
Created by Vischi on 3/26/2024 in #djs-questions
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.');
}
},
};
3 replies