🎨 Utility Command is now using guard classes

This commit is contained in:
Axel Olausson Holtenäs 2022-10-21 16:44:41 +02:00
parent 0816d0abe2
commit 5c97c21e2a
6 changed files with 26 additions and 29 deletions

View file

@ -1,32 +1,36 @@
import { SlashCommandBuilder } from "@discordjs/builders";
import { ChatInputCommandInteraction } from "discord.js";
import modules from "./modules";
export const moduleData = modules;
// Modules
import moduleAbout from "./modules/about";
import moduleAvatar from "./modules/avatar";
import modulePing from "./modules/ping";
import moduleStats from "./modules/stats";
export const builder = new SlashCommandBuilder()
.setName("utility")
.setDescription("Common utility.")
.addSubcommand(modules.about.builder)
.addSubcommand(modules.stats.builder)
.addSubcommand(modules.avatar.builder)
.addSubcommand(modules.ping.builder);
// Modules
.addSubcommand(moduleAbout.builder)
.addSubcommand(moduleStats.builder)
.addSubcommand(moduleAvatar.builder)
.addSubcommand(modulePing.builder);
// Execute the command
export const execute = async (interaction: ChatInputCommandInteraction) => {
switch (interaction.options.getSubcommand()) {
case "about":
await modules.about.execute(interaction);
await moduleAbout.execute(interaction);
break;
case "stats":
await modules.stats.execute(interaction);
await moduleStats.execute(interaction);
break;
case "avatar":
await modules.avatar.execute(interaction);
await moduleAvatar.execute(interaction);
break;
case "ping":
await modules.ping.execute(interaction);
await modulePing.execute(interaction);
break;
default:
throw new Error(

View file

@ -7,17 +7,18 @@ import {
CommandInteraction,
EmbedBuilder,
} from "discord.js";
import deferReply from "../../../../handlers/deferReply";
// Configurations
import getEmbedConfig from "../../../../helpers/getEmbedData";
// Function
export default {
metadata: { guildOnly: false, ephemeral: false },
builder: (command: SlashCommandSubcommandBuilder) => {
return command.setName("about").setDescription("About this bot!)");
},
execute: async (interaction: CommandInteraction) => {
await deferReply(interaction, false);
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);

View file

@ -1,10 +1,9 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { CommandInteraction, EmbedBuilder } from "discord.js";
import deferReply from "../../../../handlers/deferReply";
import getEmbedConfig from "../../../../helpers/getEmbedData";
export default {
metadata: { guildOnly: false, ephemeral: false },
builder: (command: SlashCommandSubcommandBuilder) => {
return command
.setName("avatar")
@ -16,6 +15,8 @@ export default {
);
},
execute: async (interaction: CommandInteraction) => {
await deferReply(interaction, false);
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);

View file

@ -1,11 +0,0 @@
import about from "./about";
import avatar from "./avatar";
import ping from "./ping";
import stats from "./stats";
export default {
avatar,
about,
stats,
ping,
};

View file

@ -2,16 +2,17 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { CommandInteraction, EmbedBuilder } from "discord.js";
// Configurations
import deferReply from "../../../../handlers/deferReply";
import getEmbedConfig from "../../../../helpers/getEmbedData";
// Function
export default {
metadata: { guildOnly: false, ephemeral: false },
builder: (command: SlashCommandSubcommandBuilder) => {
return command.setName("ping").setDescription("Ping this bot");
},
execute: async (interaction: CommandInteraction) => {
await deferReply(interaction, false);
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);

View file

@ -1,14 +1,15 @@
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { CommandInteraction, EmbedBuilder } from "discord.js";
import deferReply from "../../../../handlers/deferReply";
import getEmbedConfig from "../../../../helpers/getEmbedData";
export default {
metadata: { guildOnly: false, ephemeral: false },
builder: (command: SlashCommandSubcommandBuilder) => {
return command.setName("stats").setDescription("Check bot statistics!)");
},
execute: async (interaction: CommandInteraction) => {
await deferReply(interaction, false);
const { successColor, footerText, footerIcon } = await getEmbedConfig(
interaction.guild
);