1 |
rakin |
51 |
import BaseEvent from '../../utils/structures/BaseEvent'; |
2 |
|
|
import { GuildMember, Interaction, Message, MessageEmbed } from 'discord.js'; |
3 |
|
|
import DiscordClient from '../../client/Client'; |
4 |
|
|
import CommandOptions from '../../types/CommandOptions'; |
5 |
|
|
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
|
|
|
7 |
|
|
export default class InteractionCreateEvent extends BaseEvent { |
8 |
|
|
constructor() { |
9 |
|
|
super('interactionCreate'); |
10 |
|
|
} |
11 |
|
|
|
12 |
|
|
async run(client: DiscordClient, interaction: Interaction) { |
13 |
|
|
if (interaction.isCommand()) { |
14 |
|
|
await client.setMessage(interaction); |
15 |
|
|
|
16 |
|
|
const { commandName } = interaction; |
17 |
|
|
|
18 |
|
|
const command = await client.commands.get(commandName); |
19 |
|
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, commandName); |
20 |
|
|
|
21 |
|
|
if (command && command.supportsInteractions) { |
22 |
|
|
if (!allowed) { |
23 |
|
|
await interaction.reply({ |
24 |
|
|
embeds: [ |
25 |
|
|
new MessageEmbed() |
26 |
|
|
.setColor('#f14a60') |
27 |
|
|
.setDescription(":x: You don't have permission to run this command.") |
28 |
|
|
], |
29 |
|
|
ephemeral: true |
30 |
|
|
}); |
31 |
|
|
|
32 |
|
|
return; |
33 |
|
|
} |
34 |
|
|
|
35 |
rakin |
55 |
const options = { |
36 |
rakin |
51 |
cmdName: commandName, |
37 |
|
|
options: interaction.options, |
38 |
|
|
isInteraction: true |
39 |
rakin |
55 |
} as InteractionOptions; |
40 |
|
|
|
41 |
|
|
if (!await client.cooldown.start(interaction, options)) |
42 |
|
|
return; |
43 |
|
|
|
44 |
|
|
await command.run(client, interaction, options); |
45 |
rakin |
51 |
} |
46 |
|
|
} |
47 |
|
|
} |
48 |
|
|
} |