sapphire-support
Root Question Message
client.application?.commands.cache
is show 0import { CatCommand } from '@customs/sapphire/CatCommand';
import { ApplyOptions } from '@sapphire/decorators';
import { send } from '@sapphire/plugin-editable-commands';
import type { Message } from 'discord.js';
import { isMessageInstance } from '@sapphire/discord.js-utilities';
import type { ChatInputCommand, Command} from '@sapphire/framework';
@ApplyOptions<CatCommand.Options>({
name: 'general.ping.name',
example: 'general.ping.example',
aliases: ['ping'],
description: 'general.ping.description',
hidden: true
})
export class PingCommand extends CatCommand {
public async messageRun(message: Message) {
// throw new Error
const msg = await send(message, 'Ping?');
const content = `Pong! Bot Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${
(msg.editedTimestamp || msg.createdTimestamp) - (message.editedTimestamp || message.createdTimestamp)
}ms.`;
return send(message, content);
}
public override registerApplicationCommands(registry: ChatInputCommand.Registry) {
registry.registerChatInputCommand((builder) =>
builder.setName('ping').setDescription('Ping bot to see if it is alive')
);
}
public async chatInputRun(interaction: Command.ChatInputInteraction) {
const msg = await interaction.reply({ content: `Ping?`, ephemeral: true, fetchReply: true });
if (isMessageInstance(msg)) {
const diff = msg.createdTimestamp - interaction.createdTimestamp;
const ping = Math.round(this.container.client.ws.ping);
return interaction.editReply(`Pong 🏓! (Round trip took: ${diff}ms. Heartbeat: ${ping}ms.)`);
}
return interaction.editReply('Failed to retrieve ping :(');
}
}