Skip to content

Commit 274d7f3

Browse files
committed
update permissions check to show missing permissions
1 parent b614e06 commit 274d7f3

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

packages/commandkit/src/handlers/command-handler/validations/botPermissions.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ export default function ({ interaction, targetCommand }: BuiltInValidationParams
44
const botMember = interaction.guild?.members.me;
55

66
if (targetCommand.options?.botPermissions && botMember) {
7+
const missingPermissions: string[] = [];
8+
79
for (const permission of targetCommand.options.botPermissions) {
810
const hasPermission = botMember.permissions.has(permission);
911

1012
if (!hasPermission) {
11-
interaction.reply({
12-
content: `❌ I do not have enough permission to execute this command. Required permission: \`${permission}\``,
13-
ephemeral: true,
14-
});
15-
16-
return true;
13+
missingPermissions.push(`\`${permission.toString()}\``);
1714
}
1815
}
16+
17+
if (missingPermissions.length) {
18+
interaction.reply({
19+
content: `❌ I do not have enough permission to execute this command. Missing: ${missingPermissions.join(
20+
', ',
21+
)}`,
22+
ephemeral: true,
23+
});
24+
25+
return true;
26+
}
1927
}
2028
}

packages/commandkit/src/handlers/command-handler/validations/userPermissions.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@ export default function ({ interaction, targetCommand }: BuiltInValidationParams
44
const memberPermissions = interaction.memberPermissions;
55

66
if (targetCommand.options?.userPermissions && memberPermissions) {
7+
const missingPermissions: string[] = [];
8+
79
for (const permission of targetCommand.options.userPermissions) {
810
const hasPermission = memberPermissions.has(permission);
911

1012
if (!hasPermission) {
11-
interaction.reply({
12-
content: `❌ You do not have enough permission to run this command. Required permission: \`${permission}\``,
13-
ephemeral: true,
14-
});
15-
16-
return true;
13+
missingPermissions.push(`\`${permission.toString()}\``);
1714
}
1815
}
16+
17+
if (missingPermissions.length) {
18+
interaction.reply({
19+
content: `❌ You do not have enough permission to run this command. Missing: ${missingPermissions.join(
20+
', ',
21+
)}`,
22+
ephemeral: true,
23+
});
24+
25+
return true;
26+
}
1927
}
2028
}

0 commit comments

Comments
 (0)