JaBa/commands/Owner/reload.js

83 lines
2.5 KiB
JavaScript
Raw Permalink Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
2023-06-26 17:25:17 +05:00
i18next = require("i18next");
class Reload extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("reload")
.setDescription(client.translate("owner/reload:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("owner/reload:DESCRIPTION", null, "uk-UA"),
ru: client.translate("owner/reload:DESCRIPTION", null, "ru-RU"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel, InteractionContextType.Guild])
2023-07-05 00:58:06 +05:00
.addStringOption(option =>
option
.setName("command")
.setDescription(client.translate("common:COMMAND"))
.setDescriptionLocalizations({
uk: client.translate("common:COMMAND", null, "uk-UA"),
ru: client.translate("common:COMMAND", null, "ru-RU"),
})
.setRequired(true)
.setAutocomplete(true),
),
dirname: __dirname,
ownerOnly: true,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async execute(client, interaction) {
2024-09-19 23:58:06 +05:00
await interaction.deferReply({ ephemeral: true });
const command = interaction.options.getString("command"),
cmd = client.commands.get(command);
2022-08-14 23:09:26 +05:00
if (!cmd) return interaction.error("owner/reload:NOT_FOUND", { command }, { ephemeral: true });
2024-09-14 19:52:56 +05:00
client.unloadCommand(`../commands/${cmd.category}`, cmd.command.name);
await client.loadCommand(`../commands/${cmd.category}`, cmd.command.name);
2023-06-06 22:59:47 +05:00
i18next.reloadResources(["ru-RU", "uk-UA", "en-US"]);
interaction.success("owner/reload:SUCCESS", {
command: cmd.command.name,
2024-09-19 23:58:06 +05:00
}, { edit: true });
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").AutocompleteInteraction} interaction
* @returns
*/
async autocompleteRun(client, interaction) {
const command = interaction.options.getString("command"),
results = client.commands.filter(c => c.command.name.includes(command));
2024-01-15 23:19:59 +05:00
return await interaction.respond(
2023-07-05 00:58:06 +05:00
results
.map(c => c)
.slice(0, 25)
.map(c => ({
name: c.command.name,
value: c.command.name,
})),
);
}
}
2023-07-05 00:58:06 +05:00
module.exports = Reload;