1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 12:21:00 -05:00
Daggerbot-TS/src/commands/ping.ts

21 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-05-23 01:14:17 -04:00
import Discord from 'discord.js';
2023-04-14 06:47:58 -04:00
import TClient from '../client.js';
2023-12-24 10:21:40 -05:00
import {fetch} from 'undici';
import Formatters from '../helpers/Formatters.js';
export default class Ping {
static async run(client:TClient, interaction:Discord.ChatInputCommandInteraction<'cached'>) {
const expectedUptime:number = 16300;
if (client.uptime < expectedUptime) return interaction.reply(`I just restarted, try again in <t:${Math.round((Date.now() + expectedUptime - client.uptime) / 1000)}:R>`);
const timeOpt = {longNames: false, commas: true};
const apiResp = (await fetch('https://discordstatus.com/metrics-display/5k2rt9f7pmny/day.json')).json();
const msg = await interaction.reply({content: 'Pinging...', fetchReply: true});
msg.edit({content: null, embeds:[new client.embed().setColor('#7e96fd').addFields(
{name: 'Discord', value: Formatters.timeFormat(await apiResp.then((data:any)=>data.metrics[0].summary.mean.toFixed(0)), 3, timeOpt), inline: true},
{name: 'WebSocket', value: Formatters.timeFormat(client.ws.ping, 3, timeOpt), inline: true}
)]})
}
static data = new Discord.SlashCommandBuilder()
2023-03-05 05:04:10 -05:00
.setName('ping')
2023-08-29 10:57:13 -04:00
.setDescription('Check latency between bot and Discord API')
2023-08-28 11:21:52 -04:00
}