aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands/info/PingCommand.ts29
-rw-r--r--src/lib/extensions/BotCommand.ts6
-rw-r--r--src/listeners/client/CreateSlashCommands.ts48
3 files changed, 82 insertions, 1 deletions
diff --git a/src/commands/info/PingCommand.ts b/src/commands/info/PingCommand.ts
index 5a5b819..bb3324d 100644
--- a/src/commands/info/PingCommand.ts
+++ b/src/commands/info/PingCommand.ts
@@ -1,3 +1,5 @@
+import { CommandInteraction } from 'discord.js';
+import { Message } from 'discord.js';
import { MessageEmbed } from 'discord.js';
import { BotCommand } from '../../lib/extensions/BotCommand';
import { BotMessage } from '../../lib/extensions/BotMessage';
@@ -39,4 +41,31 @@ export default class PingCommand extends BotCommand {
embed
});
}
+
+ public async execSlash(message: CommandInteraction): Promise<void> {
+ const timestamp1 = message.createdTimestamp;
+ await message.reply('Pong!');
+ const timestamp2 = await message.fetchReply().then(m => (m as Message).createdTimestamp)
+ const botLatency = `\`\`\`\n ${Math.floor(
+ timestamp2 - timestamp1
+ )}ms \`\`\``;
+ const apiLatency = `\`\`\`\n ${Math.round(
+ this.client.ws.ping
+ )}ms \`\`\``;
+ const embed = new MessageEmbed()
+ .setTitle('Pong! 🏓')
+ .addField('Bot Latency', botLatency, true)
+ .addField('API Latency', apiLatency, true)
+ .setFooter(
+ message.user.username,
+ message.user.displayAvatarURL({ dynamic: true })
+ )
+ .setTimestamp();
+ await message.editReply({
+ content: null,
+ embeds: [
+ embed
+ ]
+ });
+ }
}
diff --git a/src/lib/extensions/BotCommand.ts b/src/lib/extensions/BotCommand.ts
index 4f62714..e86e176 100644
--- a/src/lib/extensions/BotCommand.ts
+++ b/src/lib/extensions/BotCommand.ts
@@ -1,6 +1,10 @@
-import { Command } from 'discord-akairo';
+import { Command, CommandOptions } from 'discord-akairo';
import { BotClient } from './BotClient';
export class BotCommand extends Command {
public client: BotClient;
+ constructor(id: string, options?: CommandOptions) {
+ super(id, options)
+ this.options = options
+ }
}
diff --git a/src/listeners/client/CreateSlashCommands.ts b/src/listeners/client/CreateSlashCommands.ts
new file mode 100644
index 0000000..f747f4a
--- /dev/null
+++ b/src/listeners/client/CreateSlashCommands.ts
@@ -0,0 +1,48 @@
+import { BotListener } from '../../lib/extensions/BotListener';
+
+export default class CreateSlashCommands extends BotListener {
+ constructor() {
+ super('createslashcommands', {
+ emitter: 'client',
+ event: 'ready'
+ });
+ }
+ async exec(): Promise<void> {
+ try {
+ const enabled = await this.client.application.commands.fetch();
+ for (const command of enabled) {
+ if (!this.client.commandHandler.modules.find((cmd) => cmd.id == command[1].name)) {
+ await this.client.application.commands.delete(command[1].id);
+ console.log('deleted', command[1].name);
+ }
+ }
+
+ for (const cmd of this.client.commandHandler.modules) {
+ if (cmd[1].execSlash) {
+ const found = enabled.find((i) => i.name == cmd[1].id);
+
+ const slashdata = {
+ name: cmd[1].id,
+ description: cmd[1].description.content,
+ options: cmd[1].options.slashCommandOptions
+ };
+
+ if (found?.id) {
+ if (slashdata.description !== found.description) {
+ await this.client.application.commands.edit(found.id, slashdata);
+ }
+ } else {
+ console.log('enabled', cmd[1].id);
+ await this.client.application.commands.create(slashdata);
+ }
+ }
+ }
+
+
+ return console.log('Slash commands registered');
+ } catch (e) {
+ console.log(e);
+ return console.log('Slash commands not registered, see above error.');
+ }
+ }
+}