Add ping module to utility command #338

This commit is contained in:
Axel Olausson Holtenäs 2022-06-12 12:27:35 +02:00
parent 0847ae205d
commit 7d02cf9b8d
No known key found for this signature in database
GPG key ID: 7BF6826B76382CBA
3 changed files with 57 additions and 1 deletions

View file

@ -10,7 +10,8 @@ export const builder = new SlashCommandBuilder()
.addSubcommand(modules.about.builder)
.addSubcommand(modules.stats.builder)
.addSubcommand(modules.avatar.builder);
.addSubcommand(modules.avatar.builder)
.addSubcommand(modules.ping.builder);
export const execute = async (interaction: CommandInteraction) => {
switch (interaction.options.getSubcommand()) {
@ -20,6 +21,8 @@ export const execute = async (interaction: CommandInteraction) => {
return modules.stats.execute(interaction);
case "avatar":
return modules.avatar.execute(interaction);
case "ping":
return modules.ping.execute(interaction);
default:
throw new Error(
`Unknown subcommand: ${interaction.options.getSubcommand()}`

View file

@ -1,9 +1,11 @@
import avatar from "./avatar";
import about from "./about";
import stats from "./stats";
import ping from "./ping";
export default {
avatar,
about,
stats,
ping,
};

View file

@ -0,0 +1,51 @@
// Dependencies
import {
CommandInteraction,
MessageActionRow,
MessageButton,
} from "discord.js";
// Configurations
import getEmbedConfig from "../../../../../helpers/getEmbedConfig";
import { hosterName, hosterUrl } from "../../../../../config/other";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
// Function
export default {
metadata: { guildOnly: false, ephemeral: false },
builder: (command: SlashCommandSubcommandBuilder) => {
return command.setName("ping").setDescription("Ping this bot");
},
execute: async (interaction: CommandInteraction) => {
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);
const interactionEmbed = {
title: "[:tools:] Ping",
fields: [
{
name: "📦 Deliver Latency",
value: `${Math.abs(Date.now() - interaction.createdTimestamp)} ms`,
inline: true,
},
{
name: "🤖 API Latency",
value: `${Math.round(interaction.client.ws.ping)} ms`,
inline: true,
},
],
color: successColor,
timestamp: new Date(),
footer: {
iconURL: footerIcon,
text: footerText,
},
};
await interaction.editReply({
embeds: [interactionEmbed],
});
},
};