© 2026 Hedgehog Software, LLC
import { ApplyOptions } from '@sapphire/decorators'; import { Precondition } from '@sapphire/framework'; import type { PreconditionOptions, PreconditionResult } from '@sapphire/framework'; import type { CommandInteraction, ContextMenuCommandInteraction, GuildMember } from 'discord.js'; import { container } from '@sapphire/framework'; import { Result } from '@sapphire/framework'; @ApplyOptions<PreconditionOptions>({ name: 'TicketModerate', }) export class TicketModeratePrecondition extends Precondition { public override chatInputRun(interaction: CommandInteraction): PreconditionResult { return this.checkModeratePermission(interaction); } public override contextMenuRun(interaction: ContextMenuCommandInteraction): PreconditionResult { return this.checkModeratePermission(interaction); } private checkModeratePermission(interaction: CommandInteraction | ContextMenuCommandInteraction): PreconditionResult { const member = interaction.member as GuildMember; if (member.permissions.has('Administrator') || interaction.guild?.ownerId === interaction.user.id) { return this.ok(); } const { prisma } = container; return Result.fromAsync( prisma.ticket.findFirst({ where: { channelId: interaction.channelId, status: { not: 'CLOSED' } }, include: { category: { include: { moderatorRoles: true } } } }).then(ticket => { if (!ticket) { return this.error({ message: '❌ Cette commande ne peut être utilisée que dans un ticket actif.' }); } const hasRole = ticket.category.moderatorRoles.some( role => member.roles.cache.has(role.roleId) && ['MANAGE', 'READ_WRITE'].includes(role.permission) ); if (!hasRole) { console.log('❌ Vous n\'avez pas la permission d\'utiliser cette commande.'); return this.error({ message: "❌ Vous n'avez pas la permission d'utiliser cette commande." }); } return this.ok(); }) ); } } declare module '@sapphire/framework' { interface Preconditions { TicketModerate: never; } }
Join the Discord to ask follow-up questions and connect with the community
Sapphire is a next-gen object-oriented Discord.js bot framework.
2,286 Members