Closed PassiveFr closed 1 year ago
In the module.exports you have a line where you can set the permisions needed.
My bad, for slash commands, use the method .setDefaultMemberPermissions
from the class SlashCommandBuilder
. Here is an example:
const { PermissionFlagBits } = require('discord.js');
new SlashCommandBuilder()
.setName(...)
.setDescription(...)
.setDefaultMemberPermissions(PermissionFlagBits.Administrator)
More info: https://discordjs.guide/slash-commands/permissions.html#member-permissions
Now for prefix commands, you need to use if
keyword to check whenever the user has the required permissions or not.
const { PermissionFlagBits } = require('discord.js');
if (!message.member.permissions.has(PermissionFlagBits.Administrator) {
// Your code here
};
I know how that works but if the user doesn't have perms it will not display the slash cmd but I want it like that it sends an error embed instead
It is similar to prefix command, but instead of message, it's interaction. Here is an example.
const { ChatInputCommandInteraction, SlashCommandBuilder } = require('discord.js');
const ExtendedClient = require('../../../class/ExtendedClient');
module.exports = {
structure: new SlashCommandBuilder()
.setName('')
.setDescription(''),
/**
* @param {ExtendedClient} client
* @param {ChatInputCommandInteraction<"cached">} interaction
*/
run: async (client, interaction) => {
if (!interaction.member.permissions.has(PermissionFlagsBits.Administrator)) {
await interaction.reply({
embeds: [] // <= Your embed
});
return;
};
}
};
No response, closing...
Sorry, but I didn't understand the title of this issue. Please provide more information!