For developers · 3 min read
Handling missing permissions gracefully
The code-side half of least privilege.
The main reason developers reach for Administrator is to avoid errors. The better fix is to check first and tell the user what is missing.
js
const me = interaction.guild.members.me;
const perms = interaction.channel.permissionsFor(me);
if (!perms.has(PermissionFlagsBits.ManageMessages)) {
return interaction.reply({
content: "I need **Manage Messages** in this channel to do that.",
flags: MessageFlags.Ephemeral,
});
}- Check effective permissions for the specific channel, not just server-wide roles.
- Name the missing permission in the error so server owners can fix it themselves.
- Catch error codes 50001 (Missing Access) and 50013 (Missing Permissions) as a fallback.