Skip to content

Commit

Permalink
feat: Add ping command with response time
Browse files Browse the repository at this point in the history
```
  • Loading branch information
Fyphen1223 committed May 12, 2024
1 parent 9b39a08 commit 3c6e78d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
12 changes: 11 additions & 1 deletion commands/utility/ping.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
const { getLocale } = require('../../lang/lang.js');
const { createMessageEmbed } = require('../../util/embed.js');

const guilds = require('../../data/guilds.json');

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!'),
async execute(interaction) {
await interaction.reply('Pong!');
await interaction.deferReply();
const embed = createMessageEmbed(
`🏓 - Pong! Current ping is ${discordClient.ws.ping}ms`,
interaction
);
await interaction.editReply({ embeds: [embed] });
return;
},
};
10 changes: 9 additions & 1 deletion events/interactionCreate.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fs = require('fs');

const config = require('../config.json');

const guilds = require('../data/guilds.json');
const log = require('../util/log');

const { Events } = require('discord.js');

Expand All @@ -27,7 +30,12 @@ module.exports = {
};
fs.writeFileSync(
'./data/guilds.json',
JSON.stringify(guilds, null, 2)
JSON.stringify(guilds, null, 4)
);
log.info(
`Guild ${interaction.guildId} added to guilds.json`,
config.config.log.debug,
config.config.log.saveToFile
);
}

Expand Down
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"vc": {
"noVC": "No valid VC detected. Please join a VC and try again."
}
},
"ping": "Pong! Current Ping is"
}
3 changes: 2 additions & 1 deletion lang/ja.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"vc": {
"noVC": "有効なVCが検出されませんでした。VCに参加してから試してください。"
}
},
"ping": "Pong! レイテンシは"
}
15 changes: 15 additions & 0 deletions util/embed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const config = require('../config.json');

const { EmbedBuilder } = require('discord.js');

function createMessageEmbed(content, interaction) {
const embed = new EmbedBuilder()
.setColor(config.config?.color?.info || '#000000')
.setAuthor({
name: ` | ${content}`,
iconURL: interaction.user.avatarURL({}),
});
return embed;
}

module.exports = { createMessageEmbed };

0 comments on commit 3c6e78d

Please sign in to comment.