diff --git a/src/commands/index.ts b/src/commands/index.ts index 9c30f04..1e395b0 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,6 +1,7 @@ import "./version.ts"; import "./docs.ts"; import "./tag.ts"; +import "./ping.ts"; import { registerCommands } from "../loaders/commands.ts"; await registerCommands(); diff --git a/src/commands/ping.ts b/src/commands/ping.ts new file mode 100644 index 0000000..39e4683 --- /dev/null +++ b/src/commands/ping.ts @@ -0,0 +1,30 @@ +import { defineCommand } from "../loaders/commands.ts"; +import { Bubu } from "../structs/Client.ts"; +import { InteractionCommandContext, MessageCommandContext } from "../structs/context/CommandContext.ts"; + +defineCommand({ + name: "ping", + description: "pong", + run: async(ctx: InteractionCommandContext) => { + const message = await ctx.interaction.deferReply({ + ephemeral: true, + }); + + const restPing = message.createdTimestamp - ctx.interaction.createdTimestamp; + + ctx.interaction.editReply({ + content: `🏓 WebSocket: \`${Bubu.ws.ping}ms\` | Rest: \`${restPing}ms\`` + }); + }, + runMessage: async(ctx: MessageCommandContext) => { + const message = await ctx.reply({ + content: "🏓...", + }); + + const restPing = message.createdTimestamp - ctx.message.createdTimestamp; + + message.edit({ + content: `🏓 WebSocket: \`${Bubu.ws.ping}ms\` | Rest: \`${restPing}ms\`` + }); + } +}) diff --git a/src/loaders/commands.ts b/src/loaders/commands.ts index 08e9d99..bb07fd6 100644 --- a/src/loaders/commands.ts +++ b/src/loaders/commands.ts @@ -19,7 +19,7 @@ export async function registerCommands() { .setName(d.name) .setDescription(d.description) .toJSON(), - options: d.options + options: d.options ?? [] })) } ) diff --git a/src/structs/Command.ts b/src/structs/Command.ts index b5b3205..f36a64d 100644 --- a/src/structs/Command.ts +++ b/src/structs/Command.ts @@ -31,7 +31,7 @@ export interface StringOption { export interface Command { name: string; description: string; - options: Option[]; + options?: Option[]; run?: ( context: CommandContext ) => any;