/ src / events / commandDenied.ts
commandDenied.ts
 1  import { AmethystEvent } from 'amethystjs';
 2  import { commandDeniedCode } from 'amethystjs';
 3  
 4  export default new AmethystEvent('commandDenied', (command, reason) => {
 5      const includedReplies = [
 6          { x: commandDeniedCode.GuildOnly, y: 'This command is not usable in direct messages' },
 7          {
 8              x: commandDeniedCode.UnderCooldown,
 9              y: command.interaction.client.langs.getText(command.interaction, 'commandDenied', 'underCooldown', {
10                  cooldown: Math.floor((reason.metadata?.remainingCooldownTime ?? 1000) / 1000)
11              })
12          },
13          {
14              x: commandDeniedCode.UserMissingPerms,
15              y: command.interaction.client.langs.getText(command.interaction, 'commandDenied', 'userMissingPerms', {
16                  required: reason.metadata.permissions?.need?.length ?? 0,
17                  has: reason.metadata.permissions?.got?.length ?? 0
18              })
19          },
20          {
21              x: commandDeniedCode.ClientMissingPerms,
22              y: command.interaction.client.langs.getText(command.interaction, 'commandDenied', 'clientMissingPerms', {
23                  required: reason.metadata.permissions?.need?.length ?? 0,
24                  has: reason.metadata.permissions?.got?.length ?? 0
25              })
26          }
27      ];
28      const fnt = command.interaction.replied ? 'editReply' : 'reply';
29      if (includedReplies.find((x) => x.x === reason.code)) {
30          if (!command.isMessage) {
31              command.interaction[fnt]({
32                  content: includedReplies.find((x) => x.x === reason.code).y,
33                  ephemeral: true,
34                  embeds: [],
35                  components: []
36              }).catch(() => {});
37              return;
38          }
39      }
40      command.interaction[fnt]({
41          content: reason.metadata.message,
42          embeds: [],
43          components: [],
44          ephemeral: true
45      }).catch(() => {});
46  });