Files
Nexumi/apps/bot/src/permissions.ts
smueller a17d161c06 Enhance moderation commands with locale support and permission checks
- Updated moderation commands to utilize locale for user-facing messages, improving internationalization.
- Refactored permission checks to include locale as a parameter, ensuring accurate responses based on the server's language settings.
- Added new translation keys for bot permissions and command restrictions in both German and English.
2026-07-22 11:23:10 +02:00

32 lines
805 B
TypeScript

import { type ChatInputCommandInteraction } from 'discord.js';
import { t } from '@nexumi/shared';
import type { Locale } from '@nexumi/shared';
export async function requirePermission(
interaction: ChatInputCommandInteraction,
permission: bigint,
locale: Locale
): Promise<boolean> {
const member = interaction.memberPermissions;
if (!member?.has(permission)) {
await interaction.reply({
content: t(locale, 'generic.noPermission'),
ephemeral: true
});
return false;
}
if (!interaction.guild?.members.me?.permissions.has(permission)) {
await interaction.reply({
content: t(locale, 'generic.botMissingPermission').replace(
'{permission}',
permission.toString()
),
ephemeral: true
});
return false;
}
return true;
}