Permissions
There are two sides to permissions: what your bot is allowed to do, and what the person using a command is allowed to do.
#What your bot needs
The bot gets its permissions from the invite link and from roles in the community. Ask for only what it uses. The invite link builder has presets for common bots.
If the bot is missing a permission, the call fails with a 403 and a code like MISSING_PERMISSIONS. Catch it and tell the person what’s wrong:
try {
await bot.rest.deleteMessage(message.channel_id, message.id);
} catch (err) {
if (err.status === 403) await reply('I need **Manage messages** in this channel to do that.');
else throw err;
}#What a member can do
bot.permissionsFor(message) works out what the author of a message can do in that channel. It counts their roles, the channel’s overrides, and whether they own the community:
import { Permissions, hasPermission } from '@littlespace/fluxkit';
const perms = bot.permissionsFor(message);
if (hasPermission(perms, Permissions.BAN_MEMBERS)) {
// they can ban people here
}It returns null in DMs. hasPermission treats Administrator as having everything.
#Permission names
Use the names from Permissions rather than numbers. Some of Fluxer’s values are bigger than JavaScript’s normal number limit, so they’re BigInts.
| Name | Lets someone |
|---|---|
VIEW_CHANNEL | See the channel |
SEND_MESSAGES | Send messages |
READ_MESSAGE_HISTORY | Read older messages |
EMBED_LINKS | Send embeds |
ATTACH_FILES | Upload files |
ADD_REACTIONS | Add new reactions |
MANAGE_MESSAGES | Delete other people’s messages |
PIN_MESSAGES | Pin messages |
KICK_MEMBERS | Kick people |
BAN_MEMBERS | Ban people |
MODERATE_MEMBERS | Time people out |
MANAGE_ROLES | Give and take roles below their own |
VIEW_AUDIT_LOG | Read the audit log |
MANAGE_GUILD | Change community settings and add bots |
ADMINISTRATOR | Everything |
The invite link builder shows every permission Fluxer has.
#Roles and the order they’re in
Like Discord, a bot can only give or take roles that sit below its own highest role. If a reaction-role bot can’t hand out a role, move the bot’s role above it in the community’s role settings.