From e7c377ed0cabc92ce03583e27acc19bd5d31db35 Mon Sep 17 00:00:00 2001 From: DevAndromeda <46562212+DevAndromeda@users.noreply.github.com> Date: Mon, 9 Aug 2021 19:56:23 +0545 Subject: [PATCH] feat(example): add /ping command --- example/music-bot/index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/example/music-bot/index.js b/example/music-bot/index.js index ce15ada..30d6d74 100644 --- a/example/music-bot/index.js +++ b/example/music-bot/index.js @@ -145,6 +145,10 @@ client.on("messageCreate", async (message) => { { name: "bassboost", description: "Toggles bassboost filter" + }, + { + name: "ping", + description: "Shows bot latency" } ]); @@ -155,6 +159,24 @@ client.on("messageCreate", async (message) => { client.on("interactionCreate", async (interaction) => { if (!interaction.isCommand() || !interaction.guildId) return; + if (interaction.commandName === "ping") { + await interaction.deferReply(); + const queue = player.getQueue(interaction.guild); + + return void interaction.followUp({ + embeds: [ + { + title: "⏱️ | Latency", + fields: [ + { name: "Bot Latency", value: `\`${Math.round(client.ws.ping)}ms\`` }, + { name: "Voice Latency", value: !queue ? "N/A" : `UDP: \`${queue.connection.voiceConnection.ping.udp ?? "N/A"}\`ms\nWebSocket: \`${queue.connection.voiceConnection.ping.ws ?? "N/A"}\`ms` } + ], + color: 0xFFFFFF + } + ] + }); + } + if (!(interaction.member instanceof GuildMember) || !interaction.member.voice.channel) { return void interaction.reply({ content: "You are not in a voice channel!", ephemeral: true }); }