aboutsummaryrefslogtreecommitdiff
path: root/src/listeners
diff options
context:
space:
mode:
authorTymanWasTaken <tyman@tyman.tech>2021-05-17 14:06:24 -0400
committerTymanWasTaken <tyman@tyman.tech>2021-05-17 14:06:24 -0400
commit9aee8c80067530b178612f1261c38b83683f266d (patch)
tree2ac52f719bdd77ef0265da2de02336f0759deaba /src/listeners
parent4d63c4af57a7391dd61106b79874b8e83c14971a (diff)
downloadtanzanite-9aee8c80067530b178612f1261c38b83683f266d.tar.gz
tanzanite-9aee8c80067530b178612f1261c38b83683f266d.tar.bz2
tanzanite-9aee8c80067530b178612f1261c38b83683f266d.zip
probably works idk what all I did
Diffstat (limited to 'src/listeners')
-rw-r--r--src/listeners/client/syncslashcommands.ts50
-rw-r--r--src/listeners/commands/slashError.ts48
2 files changed, 49 insertions, 49 deletions
diff --git a/src/listeners/client/syncslashcommands.ts b/src/listeners/client/syncslashcommands.ts
index eb65b97..66f530f 100644
--- a/src/listeners/client/syncslashcommands.ts
+++ b/src/listeners/client/syncslashcommands.ts
@@ -1,4 +1,3 @@
-import chalk from 'chalk';
import { BotListener } from '../../lib/extensions/BotListener';
export default class CreateSlashCommands extends BotListener {
@@ -9,53 +8,6 @@ export default class CreateSlashCommands extends BotListener {
});
}
async exec(): Promise<void> {
- try {
- const registered = await this.client.application.commands.fetch();
- for (const [, registeredCommand] of registered) {
- if (
- !this.client.commandHandler.modules.find(
- (cmd) => cmd.id == registeredCommand.name
- )
- ) {
- await this.client.application.commands.delete(registeredCommand.id);
- this.client.logger.verbose(
- chalk`{red Deleted slash command ${registeredCommand.name}}`
- );
- }
- }
-
- for (const [, botCommand] of this.client.commandHandler.modules) {
- if (botCommand.execSlash) {
- const found = registered.find((i) => i.name == botCommand.id);
-
- const slashdata = {
- name: botCommand.id,
- description: botCommand.description.content,
- options: botCommand.options.slashCommandOptions
- };
-
- if (found?.id) {
- if (slashdata.description !== found.description) {
- await this.client.application.commands.edit(found.id, slashdata);
- this.client.logger.verbose(
- chalk`{orange Edited slash command ${botCommand.id}}`
- );
- }
- } else {
- await this.client.application.commands.create(slashdata);
- this.client.logger.verbose(
- chalk`{green Created slash command ${botCommand.id}}`
- );
- }
- }
- }
-
- return this.client.logger.log(chalk.green('Slash commands registered'));
- } catch (e) {
- console.log(chalk.red(e));
- return this.client.logger.error(
- chalk`{red Slash commands not registered, see above error.}`
- );
- }
+ await this.client.util.syncSlashCommands();
}
}
diff --git a/src/listeners/commands/slashError.ts b/src/listeners/commands/slashError.ts
new file mode 100644
index 0000000..3b174a3
--- /dev/null
+++ b/src/listeners/commands/slashError.ts
@@ -0,0 +1,48 @@
+import { BotCommand } from '../../lib/extensions/BotCommand';
+import { BotListener } from '../../lib/extensions/BotListener';
+import { stripIndents } from 'common-tags';
+import { MessageEmbed } from 'discord.js';
+import { TextChannel } from 'discord.js';
+import { CommandInteraction } from 'discord.js';
+
+export default class CommandErrorListener extends BotListener {
+ constructor() {
+ super('slashError', {
+ emitter: 'commandHandler',
+ event: 'slashError'
+ });
+ }
+ async exec(
+ error: Error,
+ message: CommandInteraction,
+ command: BotCommand
+ ): Promise<void> {
+ const errorNumber = Math.floor(Math.random() * 6969696969) + 69; // hehe funy numbers
+ const errorDevEmbed = this.client.util
+ .createEmbed(this.client.util.colors.error)
+ .setTitle(`Slash Error # \`${errorNumber}\`: An error occurred`)
+ .setDescription(
+ stripIndents`**User:** <@${message.user.id}> (${message.user.tag})
+ **Slash Command:** ${command}
+ **Channel:** <#${message.channelID}> (${message.channelID})
+ **Message:** [link](https://discord.com/${message.guildID}/${message.channelID}/${message.id})`
+ )
+ .addField('Error', `${await this.client.util.haste(error.stack)}`);
+ let errorUserEmbed: MessageEmbed;
+ if (command) {
+ errorUserEmbed = this.client.util
+ .createEmbed(this.client.util.colors.error)
+ .setTitle('An error occurred')
+ .setDescription(
+ stripIndents`Whoops! It appears like something broke.
+ The developers have been notified of this. If you contact them, give them code \`${errorNumber}\`.
+ `
+ );
+ }
+ const channel = (await this.client.channels.fetch(
+ this.client.config.channels.log
+ )) as TextChannel;
+ await channel.send(errorDevEmbed);
+ if (errorUserEmbed) await message.reply(errorUserEmbed);
+ }
+}