1 |
import BaseEvent from '../../utils/structures/BaseEvent'; |
2 |
import { GuildMember } from 'discord.js'; |
3 |
import DiscordClient from '../../client/Client'; |
4 |
import { ModalSubmitInteraction } from 'discord-modals'; |
5 |
|
6 |
export default class ModalSubmitEvent extends BaseEvent { |
7 |
constructor() { |
8 |
super('modalSubmit'); |
9 |
} |
10 |
|
11 |
async run(client: DiscordClient, interaction: ModalSubmitInteraction) { |
12 |
if (!interaction.guild || !interaction.channel || interaction.channel.type === 'DM') { |
13 |
if (interaction.isRepliable()) |
14 |
await interaction.reply({ |
15 |
content: 'You cannot use this bot on DMs.', |
16 |
ephemeral: true |
17 |
}); |
18 |
|
19 |
return; |
20 |
} |
21 |
|
22 |
if ((global as any).lastCommand) { |
23 |
const cmd = client.commands.get((global as any).lastCommand); |
24 |
|
25 |
if (cmd && cmd.supportsInteractions) { |
26 |
const allowed = await client.auth.verify(interaction.member! as GuildMember, cmd); |
27 |
|
28 |
if (!allowed) { |
29 |
return; |
30 |
} |
31 |
|
32 |
await cmd.modalSubmit(client, interaction); |
33 |
} |
34 |
} |
35 |
} |
36 |
} |