feat: ping command

This commit is contained in:
Jozef Steinhübl 2023-08-25 07:27:11 +02:00
parent f3d0fad63d
commit 47a186fd7d
4 changed files with 33 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import "./version.ts"; import "./version.ts";
import "./docs.ts"; import "./docs.ts";
import "./tag.ts"; import "./tag.ts";
import "./ping.ts";
import { registerCommands } from "../loaders/commands.ts"; import { registerCommands } from "../loaders/commands.ts";
await registerCommands(); await registerCommands();

30
src/commands/ping.ts Normal file
View file

@ -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\``
});
}
})

View file

@ -19,7 +19,7 @@ export async function registerCommands() {
.setName(d.name) .setName(d.name)
.setDescription(d.description) .setDescription(d.description)
.toJSON(), .toJSON(),
options: d.options options: d.options ?? []
})) }))
} }
) )

View file

@ -31,7 +31,7 @@ export interface StringOption {
export interface Command { export interface Command {
name: string; name: string;
description: string; description: string;
options: Option[]; options?: Option[];
run?: ( run?: (
context: CommandContext<true> context: CommandContext<true>
) => any; ) => any;