3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
|
import AutoCompleteOptions from '../../types/AutoCompleteOptions'; |
7 |
|
|
8 |
export default class InteractionCreateEvent extends BaseEvent { |
export default class InteractionCreateEvent extends BaseEvent { |
9 |
constructor() { |
constructor() { |
11 |
} |
} |
12 |
|
|
13 |
async run(client: DiscordClient, interaction: Interaction) { |
async run(client: DiscordClient, interaction: Interaction) { |
|
console.log('inside'); |
|
|
|
|
14 |
if (interaction.isCommand()) { |
if (interaction.isCommand()) { |
15 |
await client.setMessage(interaction); |
await client.setMessage(interaction); |
16 |
|
|
17 |
const { commandName } = interaction; |
const { commandName } = interaction; |
18 |
|
|
19 |
const command = await client.commands.get(commandName); |
const command = await client.commands.get(commandName); |
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, commandName); |
|
20 |
|
|
21 |
if (command && command.supportsInteractions) { |
if (command && command.supportsInteractions) { |
22 |
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, command); |
23 |
|
|
24 |
if (!allowed) { |
if (!allowed) { |
25 |
await interaction.reply({ |
await interaction.reply({ |
26 |
embeds: [ |
embeds: [ |
34 |
return; |
return; |
35 |
} |
} |
36 |
|
|
37 |
await command.run(client, interaction, { |
const options = { |
38 |
cmdName: commandName, |
cmdName: commandName, |
39 |
options: interaction.options, |
options: interaction.options, |
40 |
isInteraction: true |
isInteraction: true |
41 |
} as InteractionOptions); |
} as InteractionOptions; |
42 |
|
|
43 |
|
if (!await client.cooldown.start(interaction, options)) |
44 |
|
return; |
45 |
|
|
46 |
|
await command.run(client, interaction, options); |
47 |
|
} |
48 |
|
} |
49 |
|
else if (interaction.isAutocomplete()) { |
50 |
|
await client.setMessage(interaction); |
51 |
|
|
52 |
|
const { commandName } = interaction; |
53 |
|
|
54 |
|
const command = await client.commands.get(commandName); |
55 |
|
|
56 |
|
if (command && command.supportsInteractions) { |
57 |
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, command); |
58 |
|
|
59 |
|
if (!allowed) { |
60 |
|
return; |
61 |
|
} |
62 |
|
|
63 |
|
const options = { |
64 |
|
cmdName: commandName, |
65 |
|
options: interaction.options, |
66 |
|
isInteraction: true, |
67 |
|
optionName: interaction.options.getFocused(true).name, |
68 |
|
query: interaction.options.getFocused(true).value.toString() |
69 |
|
} as AutoCompleteOptions; |
70 |
|
|
71 |
|
await command.autoComplete(client, interaction, options); |
72 |
} |
} |
73 |
} |
} |
74 |
} |
} |