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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/events/interaction/InteractionCreate.ts revision 64 by rakin, Mon Jul 29 17:28:27 2024 UTC trunk/src/events/interaction/InteractionCreateEvent.ts revision 344 by rakin, Mon Jul 29 17:29:40 2024 UTC
# Line 1  Line 1 
1  import BaseEvent from '../../utils/structures/BaseEvent';  import BaseEvent from '../../utils/structures/BaseEvent';
2  import { GuildMember, Interaction, Message, MessageEmbed } from 'discord.js';  import { GuildMember, Interaction, MessageEmbed } from 'discord.js';
3  import DiscordClient from '../../client/Client';  import DiscordClient from '../../client/Client';
 import CommandOptions from '../../types/CommandOptions';  
4  import InteractionOptions from '../../types/InteractionOptions';  import InteractionOptions from '../../types/InteractionOptions';
5  import AutoCompleteOptions from '../../types/AutoCompleteOptions';  import AutoCompleteOptions from '../../types/AutoCompleteOptions';
6    
# Line 11  export default class InteractionCreateEv Line 10  export default class InteractionCreateEv
10      }      }
11    
12      async run(client: DiscordClient, interaction: Interaction) {      async run(client: DiscordClient, interaction: Interaction) {
13          if (interaction.isCommand()) {          if (!interaction.guild || !interaction.channel || interaction.channel.type === 'DM') {
14                if (interaction.isRepliable())
15                    await interaction.reply({
16                        content: 'You cannot use this bot on DMs.',
17                        ephemeral: true
18                    });
19    
20                return;
21            }
22    
23            if (interaction.isCommand() || interaction.isContextMenu()) {
24              await client.setMessage(interaction);              await client.setMessage(interaction);
25    
26              const { commandName } = interaction;              const { commandName } = interaction;
27    
28              const command = await client.commands.get(commandName);              const command = await client.commands.get(commandName);
29    
30              if (command && command.supportsInteractions) {              if (command && ((interaction.isCommand() && command.supportsInteractions) || (interaction.isContextMenu() && command.supportsContextMenu))) {
31                  const allowed = await client.auth.verify(interaction.member! as GuildMember, command);                  const allowed = await client.auth.verify(interaction.member! as GuildMember, command);
32    
33                  if (!allowed) {                  if (!allowed) {
# Line 40  export default class InteractionCreateEv Line 49  export default class InteractionCreateEv
49                      isInteraction: true                      isInteraction: true
50                  } as InteractionOptions;                  } as InteractionOptions;
51    
52                  if (!await client.cooldown.start(interaction, options))                  await command.execute(client, interaction, options);
53                      return;                  (global as any).lastCommand = commandName;
   
                 await command.run(client, interaction, options);  
54              }              }
55          }          }
56          else if (interaction.isAutocomplete()) {          else if (interaction.isAutocomplete()) {
# Line 60  export default class InteractionCreateEv Line 67  export default class InteractionCreateEv
67                      return;                      return;
68                  }                  }
69    
70                    if (!(await command.perms(client, interaction))) {
71                        return;
72                    }
73    
74                  const options = {                  const options = {
75                      cmdName: commandName,                      cmdName: commandName,
76                      options: interaction.options,                      options: interaction.options,
# Line 69  export default class InteractionCreateEv Line 80  export default class InteractionCreateEv
80                  } as AutoCompleteOptions;                  } as AutoCompleteOptions;
81    
82                  await command.autoComplete(client, interaction, options);                  await command.autoComplete(client, interaction, options);
83                    (global as any).lastCommand = commandName;
84                }
85            }
86            else {
87                if (!(global as any).commandName)
88                    return;
89    
90                await client.setMessage(interaction);
91    
92                const command = await client.commands.get((global as any).commandName);
93    
94                if (command && command.supportsInteractions) {
95                    const allowed = await client.auth.verify(interaction.member! as GuildMember, command);
96    
97                    if (!allowed) {
98                        return;
99                    }
100                    
101                    if (!(await command.perms(client, interaction))) {
102                        return;
103                    }
104    
105                    await command.default(client, interaction);
106              }              }
107          }          }
108      }      }

Legend:
Removed from v.64  
changed lines
  Added in v.344

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26