Improve typing.
All checks were successful
Build and Publish Docker Image / build_and_push (push) Successful in 42s
All checks were successful
Build and Publish Docker Image / build_and_push (push) Successful in 42s
This commit is contained in:
58
src/utils/commands.ts
Normal file
58
src/utils/commands.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { Collection, REST, Routes } from 'discord.js';
|
||||
import * as birthday from '../commands/birthday';
|
||||
import * as corrupt from '../commands/corrupt';
|
||||
import * as countdown from '../commands/countdown';
|
||||
import * as eyecandy from '../commands/eyecandy';
|
||||
import * as game from '../commands/game';
|
||||
import * as image from '../commands/image';
|
||||
import * as imdb from '../commands/imdb';
|
||||
import * as kanye from '../commands/kanye';
|
||||
import * as magicEightBall from '../commands/magic8Ball';
|
||||
import * as payday from '../commands/payday';
|
||||
import * as plant from '../commands/plant';
|
||||
import * as reminder from '../commands/reminder';
|
||||
import * as servertime from '../commands/servertime';
|
||||
import * as taylor from '../commands/taylor';
|
||||
import * as twentyTwenty from '../commands/twentyTwenty';
|
||||
import config from '../config';
|
||||
import { Command } from './types';
|
||||
|
||||
/**
|
||||
* Get all commands as a collection.
|
||||
* @returns A collection of commands.
|
||||
*/
|
||||
export function getCommands(): Collection<string, Command> {
|
||||
const commands = new Collection<string, Command>();
|
||||
|
||||
commands.set(birthday.data.name, birthday);
|
||||
commands.set(corrupt.data.name, corrupt);
|
||||
commands.set(countdown.data.name, countdown);
|
||||
commands.set(eyecandy.data.name, eyecandy);
|
||||
commands.set(game.data.name, game);
|
||||
commands.set(image.data.name, image);
|
||||
commands.set(imdb.data.name, imdb);
|
||||
commands.set(kanye.data.name, kanye);
|
||||
commands.set(magicEightBall.data.name, magicEightBall);
|
||||
commands.set(payday.data.name, payday);
|
||||
commands.set(plant.data.name, plant);
|
||||
commands.set(reminder.data.name, reminder);
|
||||
commands.set(servertime.data.name, servertime);
|
||||
commands.set(taylor.data.name, taylor);
|
||||
commands.set(twentyTwenty.data.name, twentyTwenty);
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all slash commands globally across all Guilds.
|
||||
* @param commands A collection of commands to register.
|
||||
*/
|
||||
export async function registerSlashCommands(
|
||||
commands: Collection<string, Command>
|
||||
) {
|
||||
const commandData = commands.map((command) => command.data.toJSON());
|
||||
const rest = new REST({ version: '10' }).setToken(config.discordApiKey);
|
||||
await rest.put(Routes.applicationCommands(config.discordApplicationId), {
|
||||
body: commandData,
|
||||
});
|
||||
}
|
||||
18
src/utils/types.ts
Normal file
18
src/utils/types.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
SlashCommandBuilder,
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
SlashCommandOptionsOnlyBuilder,
|
||||
ChatInputCommandInteraction,
|
||||
} from 'discord.js';
|
||||
|
||||
// Create a generic type to cover all relevant SlashCommandBuilder types
|
||||
export type CommandBuilder =
|
||||
| SlashCommandBuilder
|
||||
| SlashCommandSubcommandsOnlyBuilder
|
||||
| SlashCommandOptionsOnlyBuilder;
|
||||
|
||||
// Define the Command interface
|
||||
export interface Command {
|
||||
data: CommandBuilder; // Use the generic CommandBuilder type
|
||||
execute: (interaction: ChatInputCommandInteraction) => Promise<void>;
|
||||
}
|
||||
Reference in New Issue
Block a user