JaBa/commands/Administration/autorole.js

77 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, PermissionsBitField, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
2022-08-08 18:19:56 +05:00
const BaseCommand = require("../../base/BaseCommand");
class Autorole extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
2022-08-08 18:19:56 +05:00
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("autorole")
.setDescription(client.translate("administration/autorole:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("administration/autorole:DESCRIPTION", null, "uk-UA"),
ru: client.translate("administration/autorole:DESCRIPTION", null, "ru-RU"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.Guild])
2023-07-03 21:13:08 +05:00
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild)
2023-07-05 00:58:06 +05:00
.addBooleanOption(option =>
option
.setName("state")
.setDescription(client.translate("common:STATE"))
.setDescriptionLocalizations({
uk: client.translate("common:STATE", null, "uk-UA"),
ru: client.translate("common:STATE", null, "ru-RU"),
})
.setRequired(true),
)
.addRoleOption(option =>
option
.setName("role")
.setDescription(client.translate("common:ROLE"))
.setDescriptionLocalizations({
uk: client.translate("common:ROLE", null, "uk-UA"),
ru: client.translate("common:ROLE", null, "ru-RU"),
}),
),
2022-08-08 18:19:56 +05:00
dirname: __dirname,
ownerOnly: false,
2022-08-08 18:19:56 +05:00
});
}
2022-08-08 18:19:56 +05:00
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
2022-08-08 18:19:56 +05:00
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
2024-02-09 23:26:57 +05:00
async execute(client, interaction) {
const guildData = interaction.data.guild,
state = interaction.options.getBoolean("state"),
role = interaction.options.getRole("role");
2022-08-08 18:19:56 +05:00
2024-02-09 23:26:57 +05:00
guildData.plugins.autorole = {
enabled: state,
role,
};
if (state && role) {
2024-02-09 23:26:57 +05:00
await guildData.save();
2022-08-08 18:19:56 +05:00
interaction.success("administration/autorole:ENABLED", {
role: role.toString(),
2022-08-08 18:19:56 +05:00
});
} else {
2024-02-09 23:26:57 +05:00
guildData.plugins.autorole.enabled = false;
2024-02-09 23:26:57 +05:00
await guildData.save();
2022-08-08 18:19:56 +05:00
interaction.success("administration/autorole:DISABLED");
2022-08-08 18:19:56 +05:00
}
}
}
2023-07-05 00:58:06 +05:00
module.exports = Autorole;