Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Guild, User } = require(`${process.cwd()}/src/database/blacklistSchema.js`);
- const pEmbed = require(`${process.cwd()}/src/functions/paginationEmbed.js`);
- const { EmbedBuilder, ApplicationCommandType, ApplicationCommandOptionType } = require('discord.js');
- const ROYAL_BLUE = '#4169E1';
- module.exports = {
- name: "blacklist",
- description: "Manage the blacklist for users and guilds.",
- category: "moderation",
- userPerms: ["ManageGuild"],
- botPerms: ["ManageGuild"],
- cooldown: 5,
- guildOnly: false,
- ownerOnly: false,
- toggleOff: true,
- nsfwOnly: false,
- maintenance: false,
- type: ApplicationCommandType.ChatInput,
- options: [
- {
- name: "user",
- description: "Manage blacklisted users.",
- type: ApplicationCommandOptionType.SubcommandGroup,
- options: [
- {
- name: "add",
- description: "Add a user to the blacklist.",
- type: ApplicationCommandOptionType.Subcommand,
- options: [
- {
- name: "user_id",
- description: "The user ID to blacklist.",
- type: ApplicationCommandOptionType.String,
- required: true,
- },
- {
- name: "reason",
- description: "The reason for blacklisting.",
- type: ApplicationCommandOptionType.String,
- required: false,
- },
- ],
- },
- {
- name: "remove",
- description: "Remove a user from the blacklist.",
- type: ApplicationCommandOptionType.Subcommand,
- options: [
- {
- name: "user_id",
- description: "The user ID to unblacklist.",
- type: ApplicationCommandOptionType.String,
- required: true,
- },
- ],
- },
- {
- name: "view",
- description: "View all blacklisted users.",
- type: ApplicationCommandOptionType.Subcommand,
- },
- ],
- },
- {
- name: "guild",
- description: "Manage blacklisted guilds.",
- type: ApplicationCommandOptionType.SubcommandGroup,
- options: [
- {
- name: "add",
- description: "Add a guild to the blacklist.",
- type: ApplicationCommandOptionType.Subcommand,
- options: [
- {
- name: "guild_id",
- description: "The guild ID to blacklist.",
- type: ApplicationCommandOptionType.String,
- required: true,
- },
- {
- name: "reason",
- description: "The reason for blacklisting.",
- type: ApplicationCommandOptionType.String,
- required: false,
- },
- ],
- },
- {
- name: "remove",
- description: "Remove a guild from the blacklist.",
- type: ApplicationCommandOptionType.Subcommand,
- options: [
- {
- name: "guild_id",
- description: "The guild ID to unblacklist.",
- type: ApplicationCommandOptionType.String,
- required: true,
- },
- ],
- },
- {
- name: "view",
- description: "View all blacklisted guilds.",
- type: ApplicationCommandOptionType.Subcommand,
- },
- ],
- },
- ],
- run: async (client, interaction) => {
- const subcommandGroup = interaction.options.getSubcommandGroup();
- const subcommand = interaction.options.getSubcommand();
- try {
- if (subcommandGroup === "user") {
- if (subcommand === "add") {
- const userId = interaction.options.getString("user_id");
- const reason = interaction.options.getString("reason") || "No reason provided.";
- if (!/^\d+$/.test(userId)) {
- return await interaction.reply({ content: "Please provide a valid user ID.", ephemeral: true });
- }
- const existingUser = await User.findOne({ userId });
- if (existingUser) {
- return await interaction.reply({ content: `User <@${userId}> is already blacklisted.`, ephemeral: true });
- }
- await new User({ userId, reason }).save();
- return await interaction.reply({ content: `User <@${userId}> has been blacklisted. Reason: ${reason}`, ephemeral: true });
- }
- if (subcommand === "remove") {
- const userId = interaction.options.getString("user_id");
- if (!/^\d+$/.test(userId)) {
- return await interaction.reply({ content: "Please provide a valid user ID.", ephemeral: true });
- }
- const existingUser = await User.findOneAndDelete({ userId });
- if (!existingUser) {
- return await interaction.reply({ content: `User <@${userId}> is not blacklisted.`, ephemeral: true });
- }
- return await interaction.reply({ content: `User <@${userId}> has been removed from the blacklist.`, ephemeral: true });
- }
- if (subcommand === "view") {
- const blacklistedUsers = await User.find({});
- if (blacklistedUsers.length === 0) {
- return await interaction.reply({ content: "There are no blacklisted users.", ephemeral: true });
- }
- const embeds = blacklistedUsers.map(user =>
- new EmbedBuilder()
- .setColor(ROYAL_BLUE)
- .setAuthor({ name: `Blacklisted User: <@${user.userId}>`, iconURL: client.user.displayAvatarURL() })
- .addFields(
- { name: 'User ID', value: user.userId, inline: true },
- { name: 'Reason', value: user.reason || 'No reason provided', inline: true },
- { name: 'Added On', value: new Date(user._id.getTimestamp()).toLocaleDateString(), inline: true }
- )
- .setTimestamp()
- .setFooter({ text: client.embed.footertext, iconURL: client.embed.footericon })
- );
- pEmbed(client, interaction, embeds, "60s", false);
- }
- }
- if (subcommandGroup === "guild") {
- if (subcommand === "add") {
- const guildId = interaction.options.getString("guild_id");
- const reason = interaction.options.getString("reason") || "No reason provided.";
- if (!/^\d+$/.test(guildId)) {
- return await interaction.reply({ content: "Please provide a valid guild ID.", ephemeral: true });
- }
- const existingGuild = await Guild.findOne({ guildId });
- if (existingGuild) {
- return await interaction.reply({ content: `Guild with ID \`${guildId}\` is already blacklisted.`, ephemeral: true });
- }
- await new Guild({ guildId, reason }).save();
- return await interaction.reply({ content: `Guild with ID \`${guildId}\` has been blacklisted. Reason: ${reason}`, ephemeral: true });
- }
- if (subcommand === "remove") {
- const guildId = interaction.options.getString("guild_id");
- if (!/^\d+$/.test(guildId)) {
- return await interaction.reply({ content: "Please provide a valid guild ID.", ephemeral: true });
- }
- const existingGuild = await Guild.findOneAndDelete({ guildId });
- if (!existingGuild) {
- return await interaction.reply({ content: `Guild with ID \`${guildId}\` is not blacklisted.`, ephemeral: true });
- }
- return await interaction.reply({ content: `Guild with ID \`${guildId}\` has been removed from the blacklist.`, ephemeral: true });
- }
- if (subcommand === "view") {
- const blacklistedGuilds = await Guild.find({});
- if (blacklistedGuilds.length === 0) {
- return await interaction.reply({ content: "There are no blacklisted guilds.", ephemeral: true });
- }
- const embeds = blacklistedGuilds.map(guild =>
- new EmbedBuilder()
- .setColor(ROYAL_BLUE)
- .setAuthor({ name: `Blacklisted Guild: ${guild.guildId}`, iconURL: client.user.displayAvatarURL() })
- .addFields(
- { name: 'Guild ID', value: guild.guildId, inline: true },
- { name: 'Reason', value: guild.reason || 'No reason provided', inline: true },
- { name: 'Added On', value: new Date(guild._id.getTimestamp()).toLocaleDateString(), inline: true }
- )
- .setTimestamp()
- .setFooter({ text: client.embed.footertext, iconURL: client.embed.footericon })
- );
- pEmbed(client, interaction, embeds, "60s", false);
- }
- }
- } catch (error) {
- console.error("Error in blacklist command:", error);
- await interaction.reply({ content: "An error occurred while processing your command. Please try again later.", ephemeral: true });
- }
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement