From 09c7a69f8d7fb139eba293242238d109c779717e Mon Sep 17 00:00:00 2001 From: Ryan David Ward Date: Wed, 3 Apr 2024 15:19:29 -0500 Subject: [PATCH] Add permission check to expense command --- commands/bank/expense.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/commands/bank/expense.ts b/commands/bank/expense.ts index 4aaf483..b91ca32 100644 --- a/commands/bank/expense.ts +++ b/commands/bank/expense.ts @@ -18,6 +18,15 @@ export const data = new SlashCommandBuilder() export async function execute(interaction: CommandInteraction) { try { + // Check if the member has the required roles + const member = await interaction.guild?.members.fetch(interaction.user.id); + const hasPermission = member?.roles.cache.some( + role => role.name === 'Officer' || role.name === 'Treasurer', + ); + if (!hasPermission) { + throw new Error('You do not have permission to use this command.'); + } + const { options } = interaction; const amount = options.get('amount')?.value as number; const description = options.get('description')?.value as string;