/[sudobot]/trunk/src/events/interaction/InteractionCreateEvent.ts
ViewVC logotype

Annotation of /trunk/src/events/interaction/InteractionCreateEvent.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations)
Mon Jul 29 17:28:27 2024 UTC (8 months, 2 weeks ago) by rakin
Original Path: trunk/src/events/interaction/InteractionCreate.ts
File MIME type: application/typescript
File size: 2714 byte(s)
Added slash commands autocompletion support
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 rakin 64 import AutoCompleteOptions from '../../types/AutoCompleteOptions';
7 rakin 51
8     export default class InteractionCreateEvent extends BaseEvent {
9     constructor() {
10     super('interactionCreate');
11     }
12    
13     async run(client: DiscordClient, interaction: Interaction) {
14     if (interaction.isCommand()) {
15     await client.setMessage(interaction);
16    
17     const { commandName } = interaction;
18    
19     const command = await client.commands.get(commandName);
20    
21     if (command && command.supportsInteractions) {
22 rakin 58 const allowed = await client.auth.verify(interaction.member! as GuildMember, command);
23    
24 rakin 51 if (!allowed) {
25     await interaction.reply({
26     embeds: [
27     new MessageEmbed()
28     .setColor('#f14a60')
29     .setDescription(":x: You don't have permission to run this command.")
30     ],
31     ephemeral: true
32     });
33    
34     return;
35     }
36    
37 rakin 55 const options = {
38 rakin 51 cmdName: commandName,
39     options: interaction.options,
40     isInteraction: true
41 rakin 55 } as InteractionOptions;
42    
43     if (!await client.cooldown.start(interaction, options))
44     return;
45    
46     await command.run(client, interaction, options);
47 rakin 51 }
48     }
49 rakin 64 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 rakin 51 }
75     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26