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) { |
14 |
console.log('inside'); |
if (!interaction.guild || !interaction.channel || interaction.channel.type === 'DM') { |
15 |
|
if (interaction.isRepliable()) |
16 |
|
await interaction.reply({ |
17 |
|
content: 'You cannot use this bot on DMs.', |
18 |
|
ephemeral: true |
19 |
|
}); |
20 |
|
|
21 |
|
return; |
22 |
|
} |
23 |
|
|
24 |
if (interaction.isCommand()) { |
if (interaction.isCommand()) { |
25 |
await client.setMessage(interaction); |
await client.setMessage(interaction); |
27 |
const { commandName } = interaction; |
const { commandName } = interaction; |
28 |
|
|
29 |
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); |
|
30 |
|
|
31 |
if (command && command.supportsInteractions) { |
if (command && command.supportsInteractions) { |
32 |
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, command); |
33 |
|
|
34 |
if (!allowed) { |
if (!allowed) { |
35 |
await interaction.reply({ |
await interaction.reply({ |
36 |
embeds: [ |
embeds: [ |
44 |
return; |
return; |
45 |
} |
} |
46 |
|
|
47 |
await command.run(client, interaction, { |
const options = { |
48 |
cmdName: commandName, |
cmdName: commandName, |
49 |
options: interaction.options, |
options: interaction.options, |
50 |
isInteraction: true |
isInteraction: true |
51 |
} as InteractionOptions); |
} as InteractionOptions; |
52 |
|
|
53 |
|
if (!await client.cooldown.start(interaction, options)) |
54 |
|
return; |
55 |
|
|
56 |
|
await command.run(client, interaction, options); |
57 |
|
} |
58 |
|
} |
59 |
|
else if (interaction.isAutocomplete()) { |
60 |
|
await client.setMessage(interaction); |
61 |
|
|
62 |
|
const { commandName } = interaction; |
63 |
|
|
64 |
|
const command = await client.commands.get(commandName); |
65 |
|
|
66 |
|
if (command && command.supportsInteractions) { |
67 |
|
const allowed = await client.auth.verify(interaction.member! as GuildMember, command); |
68 |
|
|
69 |
|
if (!allowed) { |
70 |
|
return; |
71 |
|
} |
72 |
|
|
73 |
|
const options = { |
74 |
|
cmdName: commandName, |
75 |
|
options: interaction.options, |
76 |
|
isInteraction: true, |
77 |
|
optionName: interaction.options.getFocused(true).name, |
78 |
|
query: interaction.options.getFocused(true).value.toString() |
79 |
|
} as AutoCompleteOptions; |
80 |
|
|
81 |
|
await command.autoComplete(client, interaction, options); |
82 |
} |
} |
83 |
} |
} |
84 |
} |
} |