forked from SudhanPlayz/Discord-MusicBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create ping.js simple Ping command inspired by @XstreamSpeed This version fixes the mistakes from the previous PR, which include but do not limit themselves to: Wrong scopes, mismatched parenthesis, undefined methods and variables, redundant information provided by other commands... * fix hanging login on replit systems * Update index.js changed scope
- Loading branch information
1 parent
d2f505a
commit a3fc74d
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const { MessageEmbed } = require("discord.js"); | ||
const SlashCommand = require("../../lib/SlashCommand"); | ||
|
||
const command = new SlashCommand() | ||
.setName("ping") | ||
.setDescription("View the bot's latency") | ||
.setRun(async (client, interaction, options) => { | ||
let msg = await interaction.channel.send({ | ||
embeds: [new MessageEmbed() | ||
.setDescription("🏓 | Fetching ping...") | ||
.setColor("#6F8FAF") | ||
] | ||
}) | ||
|
||
let zap = "⚡"; | ||
let green = "🟢"; | ||
let red = "🔴"; | ||
let yellow = "🟡"; | ||
|
||
var botState = zap; | ||
var apiState = zap; | ||
|
||
let apiPing = client.ws.ping; | ||
let botPing = Math.floor(msg.createdAt - interaction.createdAt); | ||
|
||
if (apiPing >= 40 && apiPing < 200) { | ||
apiState = green; | ||
} else if (apiPing >= 200 && apiPing < 400) { | ||
apiState = yellow; | ||
} else if (apiPing >= 400) { | ||
apiState = red; | ||
} | ||
|
||
if (botPing >= 40 && botPing < 200) { | ||
botState = green; | ||
} else if (botPing >= 200 && botPing < 400) { | ||
botState = yellow; | ||
} else if (botPing >= 400) { | ||
botState = red; | ||
} | ||
|
||
msg.delete(); | ||
interaction.reply({ | ||
embeds: [new MessageEmbed() | ||
.setTitle("🏓 | Pong!") | ||
.addField("API Latency", `\`\`\`yml\n${apiState} | ${apiPing}ms\`\`\``, true) | ||
.addField("Bot Latency", `\`\`\`yml\n${botState} | ${botPing}ms\`\`\``, true) | ||
.setColor(client.config.embedColor) | ||
.setFooter({ | ||
text: `Requested by ${interaction.user.tag}`, | ||
iconURL: (interaction.user.avatarURL()) | ||
}) | ||
] | ||
}) | ||
}); | ||
|
||
module.exports = command; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters