File tree 5 files changed +41
-3
lines changed
5 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -8,5 +8,5 @@ export abstract class Command {
8
8
9
9
public readonly name : string ;
10
10
abstract execute ( interaction : CommandInteraction ) : Promise < void > ;
11
- abstract register ( ) : SlashCommandBuilder ;
11
+ abstract register ( ) : SlashCommandBuilder | Omit < SlashCommandBuilder , "addSubcommandGroup" | "addSubcommand" > ;
12
12
}
Original file line number Diff line number Diff line change
1
+ import { Command } from "../Command";
2
+ import { CommandInteraction } from "discord.js";
3
+ import { SlashCommandBuilder } from "@discordjs/builders";
4
+
5
+ // set the class name, the export at the bottom and the file name to your desired command name (same as the one in the register function)
6
+ class CommandName extends Command {
7
+ constructor() {
8
+ super("bunny"); // the name under which the bot internally stores your command (should be the same as the named set in `register`, must be unique)
9
+ }
10
+
11
+ async execute(interaction: CommandInteraction): Promise<void> {
12
+ // put the logic of your command here
13
+ // for example:
14
+ const num = interaction.options.getInteger("amount") || 1;
15
+ await interaction.reply("🐇".repeat(num));
16
+ }
17
+
18
+ register(): SlashCommandBuilder | Omit<SlashCommandBuilder, "addSubcommandGroup" | "addSubcommand"> {
19
+ // set the name and description shown in discord here (these are necessary)
20
+ // (name: string.length = 1-32, description string.length = 1-100)(the name has to be lowercase!)
21
+ // here you can also add things like options to your command
22
+ // see more under https://discord.js.org/#/docs/builders/stable/class/SlashCommandBuilder
23
+ return new SlashCommandBuilder()
24
+ .setName("bunny")
25
+ .setDescription("shows you a cute bunny")
26
+ .addIntegerOption(option => option.setName("amount").setDescription("number of bunnies").setRequired(false));
27
+ }
28
+ }
29
+
30
+ export default new CommandName();
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ class PingCommand extends Command {
12
12
await interaction . reply ( `Pong! (Bot ping: ${ botping } ms)` ) ;
13
13
}
14
14
15
- register ( ) : SlashCommandBuilder {
15
+ register ( ) : SlashCommandBuilder | Omit < SlashCommandBuilder , "addSubcommandGroup" | "addSubcommand" > {
16
16
return new SlashCommandBuilder ( ) . setName ( "ping" ) . setDescription ( "Replies pong and the bots ping." ) ;
17
17
}
18
18
}
Original file line number Diff line number Diff line change
1
+ // set the function name to the event name
2
+ // and edit the parameter to fit in its type and name to the event
3
+ export default async function interactionName(args: unknown) {
4
+ // do things if the event occurs
5
+ }
Original file line number Diff line number Diff line change @@ -41,7 +41,10 @@ async function updateRegisteredCommands(client: Client) {
41
41
}
42
42
}
43
43
44
- function commandsEqual ( c1 : ApplicationCommand , c2 : SlashCommandBuilder ) : boolean {
44
+ function commandsEqual (
45
+ c1 : ApplicationCommand ,
46
+ c2 : SlashCommandBuilder | Omit < SlashCommandBuilder , "addSubcommandGroup" | "addSubcommand" >
47
+ ) : boolean {
45
48
return (
46
49
c1 . name === c2 . name &&
47
50
c1 . description === c2 . description &&
You can’t perform that action at this time.
0 commit comments