mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
feat: ping command
This commit is contained in:
1 parent
78d429808a
commit
78424c1535
2 files changed
+40
-6
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import { CommandRegistry } from '../events/interactionCreate.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
handlesInteraction: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('ping'))
|
||||
.setDescription('Check if the bot is alive'),
|
||||
|
||||
async execute(interaction) {
|
||||
const executionStart = new Date().getTime();
|
||||
await interaction.editReply('Pong 🏓');
|
||||
const executionTime = new Date().getTime() - executionStart;
|
||||
interaction.editReply(`Pong 🏓 - ${executionTime}ms`);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
@@ -19,6 +19,7 @@ import eligible from '../commands/eligible.js';
|
||||
import help from '../commands/help.js';
|
||||
import inactive from '../commands/inactive.js';
|
||||
import ownedtanks from '../commands/ownedtanks.js';
|
||||
import ping from '../commands/ping.js';
|
||||
import playerachievements from '../commands/playerachievements.js';
|
||||
import playerinfo from '../commands/playerinfo.js';
|
||||
import searchclans from '../commands/searchclans.js';
|
||||
@@ -40,17 +41,25 @@ import { handleError } from './error.js';
|
||||
export type CommandReturnable = EmbedBuilder | ButtonBuilder | JSX.Element;
|
||||
export type RichCommandReturnable = CommandReturnable | CommandReturnable[];
|
||||
|
||||
export interface CommandRegistry {
|
||||
export type CommandRegistry = {
|
||||
inDevelopment: boolean;
|
||||
inProduction: boolean;
|
||||
inPublic: boolean;
|
||||
|
||||
command: Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
|
||||
execute: (
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) => RichCommandReturnable | Promise<RichCommandReturnable>;
|
||||
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
|
||||
}
|
||||
} & (
|
||||
| {
|
||||
handlesInteraction?: false;
|
||||
execute: (
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) => RichCommandReturnable | Promise<RichCommandReturnable>;
|
||||
}
|
||||
| {
|
||||
handlesInteraction: true;
|
||||
execute: (interaction: ChatInputCommandInteraction<CacheType>) => void;
|
||||
}
|
||||
);
|
||||
|
||||
const rest = new REST().setToken(DISCORD_TOKEN);
|
||||
|
||||
@@ -70,6 +79,7 @@ const commands = (
|
||||
tankstats,
|
||||
today,
|
||||
verify,
|
||||
ping,
|
||||
] as CommandRegistry[]
|
||||
).reduce<Record<string, CommandRegistry>>((accumulator, registry) => {
|
||||
return { ...accumulator, [registry.command.name]: registry };
|
||||
@@ -161,6 +171,9 @@ export default async function interactionCreate(
|
||||
|
||||
try {
|
||||
const result = await command.execute(interaction);
|
||||
|
||||
if (command.handlesInteraction) return;
|
||||
|
||||
const normalizedResult = Array.isArray(result) ? result : [result];
|
||||
const reply: InteractionEditReplyOptions = {};
|
||||
|
||||
@@ -182,7 +195,7 @@ export default async function interactionCreate(
|
||||
reply.components[0] as ActionRowBuilder<ButtonBuilder>
|
||||
).addComponents(item);
|
||||
} else {
|
||||
const image = await render(item);
|
||||
const image = await render(item!);
|
||||
if (!reply.files) reply.files = [];
|
||||
reply.files.push(image);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user