From b2260637bc86c1cb2e9d9a2d24ed81a376fd8d4f Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 19 Sep 2021 01:22:42 +0100 Subject: [PATCH] Add Ping Command --- .../me/goudham/bot/command/misc/Ping.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/me/goudham/bot/command/misc/Ping.java diff --git a/src/main/java/me/goudham/bot/command/misc/Ping.java b/src/main/java/me/goudham/bot/command/misc/Ping.java new file mode 100644 index 00000000..89a638a6 --- /dev/null +++ b/src/main/java/me/goudham/bot/command/misc/Ping.java @@ -0,0 +1,28 @@ +package me.goudham.bot.command.misc; + +import jakarta.inject.Inject; +import me.goudham.bot.command.ISlashCommand; +import me.goudham.command.annotation.SlashCommand; +import me.goudham.service.EmbedGenerator; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.InteractionHook; + +@SlashCommand(name = "ping", description = "Display the latency of the bot", isVisible = true) +public class Ping implements ISlashCommand { + private final EmbedGenerator embedGenerator; + + @Inject + public Ping(EmbedGenerator embedGenerator) { + this.embedGenerator = embedGenerator; + } + + @Override + public void handle(SlashCommandEvent event) { + event.deferReply(false).queue(); + InteractionHook hook = event.getHook(); + JDA jda = event.getJDA(); + + jda.getRestPing().queue(ping -> hook.sendMessageEmbeds(embedGenerator.getBaseEmbed().setDescription("**Rest ping: " + ping + "ms**\n**WS ping: " + jda.getGatewayPing() + "ms**").build()).queue()); + } +} \ No newline at end of file