Skip to content

Commit ed10db2

Browse files
chore: templates (#7)
* Type error fix * Samples * prettify * formatting src/events/EventSample.disable Co-authored-by: Antti <[email protected]> * Update CommandSample.disable * Update src/commands/CommandSample.disable Co-authored-by: Antti <[email protected]> * Update src/commands/CommandSample.disable Co-authored-by: Antti <[email protected]> * Rename CommandSample.disable to CommandSample.ts.disable * Rename EventSample.disable to EventSample.ts.disable * comment change * return type Co-authored-by: Antti <[email protected]>
1 parent 9cef32b commit ed10db2

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

src/Command.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export abstract class Command {
88

99
public readonly name: string;
1010
abstract execute(interaction: CommandInteraction): Promise<void>;
11-
abstract register(): SlashCommandBuilder;
11+
abstract register(): SlashCommandBuilder | Omit<SlashCommandBuilder, "addSubcommandGroup" | "addSubcommand">;
1212
}

src/commands/CommandSample.ts.disable

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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();

src/commands/PingCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class PingCommand extends Command {
1212
await interaction.reply(`Pong! (Bot ping: ${botping}ms)`);
1313
}
1414

15-
register(): SlashCommandBuilder {
15+
register(): SlashCommandBuilder | Omit<SlashCommandBuilder, "addSubcommandGroup" | "addSubcommand"> {
1616
return new SlashCommandBuilder().setName("ping").setDescription("Replies pong and the bots ping.");
1717
}
1818
}

src/events/EventSample.ts.disable

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
}

src/events/ready.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ async function updateRegisteredCommands(client: Client) {
4141
}
4242
}
4343

44-
function commandsEqual(c1: ApplicationCommand, c2: SlashCommandBuilder): boolean {
44+
function commandsEqual(
45+
c1: ApplicationCommand,
46+
c2: SlashCommandBuilder | Omit<SlashCommandBuilder, "addSubcommandGroup" | "addSubcommand">
47+
): boolean {
4548
return (
4649
c1.name === c2.name &&
4750
c1.description === c2.description &&

0 commit comments

Comments
 (0)