1 |
import { ModalSubmitInteraction } from 'discord-modals'; |
import { ModalSubmitInteraction } from 'discord-modals'; |
2 |
import { PermissionResolvable, AutocompleteInteraction, CommandInteraction, CommandInteractionOption, ContextMenuInteraction, Interaction, Message, MessageEditOptions, MessageOptions, MessagePayload, WebhookEditMessageOptions } from 'discord.js'; |
import { PermissionResolvable, AutocompleteInteraction, CommandInteraction, CommandInteractionOption, ContextMenuInteraction, Interaction, Message, MessageEditOptions, MessageOptions, MessagePayload, WebhookEditMessageOptions, SelectMenuInteraction, ButtonInteraction, GuildMember } from 'discord.js'; |
3 |
import DiscordClient from '../../client/Client'; |
import DiscordClient from '../../client/Client'; |
4 |
import AutoCompleteOptions from '../../types/AutoCompleteOptions'; |
import AutoCompleteOptions from '../../types/AutoCompleteOptions'; |
5 |
import CommandOptions from '../../types/CommandOptions'; |
import CommandOptions from '../../types/CommandOptions'; |
49 |
return (await msg.editReply(options as string | MessagePayload | WebhookEditMessageOptions)) as Message; |
return (await msg.editReply(options as string | MessagePayload | WebhookEditMessageOptions)) as Message; |
50 |
} |
} |
51 |
|
|
52 |
|
async perms(client: DiscordClient, message: Message | Interaction) { |
53 |
|
let member: GuildMember | null = null; |
54 |
|
|
55 |
|
if (message.member && !(message.member instanceof GuildMember)) { |
56 |
|
try { |
57 |
|
member = (await message.guild?.members.fetch(message.member!.user.id)) ?? null; |
58 |
|
} |
59 |
|
catch (e) { |
60 |
|
console.log(e); |
61 |
|
return false; |
62 |
|
} |
63 |
|
} |
64 |
|
else { |
65 |
|
member = message.member; |
66 |
|
} |
67 |
|
|
68 |
|
for await (let permission of this.permissions) { |
69 |
|
if (!member?.permissions.has(permission, true)) { |
70 |
|
if (message instanceof Interaction && !message.isRepliable()) |
71 |
|
return; |
72 |
|
|
73 |
|
await message.reply({ |
74 |
|
embeds: [ |
75 |
|
{ |
76 |
|
description: ":x: You don't have enough permissions to run this command.", |
77 |
|
color: 0xf14a60 |
78 |
|
} |
79 |
|
] |
80 |
|
}); |
81 |
|
|
82 |
|
return false; |
83 |
|
} |
84 |
|
} |
85 |
|
|
86 |
|
return true; |
87 |
|
} |
88 |
|
|
89 |
|
async execute(client: DiscordClient, message: Message | Interaction, options: CommandOptions | InteractionOptions) { |
90 |
|
if (!(await this.perms(client, message))) { |
91 |
|
return; |
92 |
|
} |
93 |
|
|
94 |
|
await this.run(client, message, options); |
95 |
|
} |
96 |
|
|
97 |
abstract run(client: DiscordClient, message: Message | Interaction, options: CommandOptions | InteractionOptions): Promise<void>; |
abstract run(client: DiscordClient, message: Message | Interaction, options: CommandOptions | InteractionOptions): Promise<void>; |
98 |
} |
} |