Untitled
unknown
plain_text
19 days ago
4.2 kB
3
Indexable
const { SlashCommandBuilder, PermissionFlagsBits, EmbedBuilder, ChannelType } = require('discord.js'); const emotes = require('../../emotes.json'); module.exports = { data: new SlashCommandBuilder() .setName('setpermissions') .setDescription('Set permissions for all channels in a category') .addStringOption(option => option.setName('category') .setDescription('The ID of the category') .setRequired(true)) .addStringOption(option => option.setName('type') .setDescription('Select channel type') .setRequired(true) .addChoices( { name: 'Voice', value: 'GuildVoice' }, { name: 'Text', value: 'GuildText' } )) .addStringOption(option => option.setName('permissions') .setDescription('Select permissions to apply') .setRequired(true) .addChoices( { name: 'View Channel', value: 'ViewChannel' }, { name: 'Send Messages', value: 'SendMessages' }, { name: 'Manage Messages', value: 'ManageMessages' }, { name: 'Connect', value: 'Connect' }, { name: 'Speak', value: 'Speak' }, { name: 'Mute Members', value: 'MuteMembers' }, { name: 'Deafen Members', value: 'DeafenMembers' }, { name: 'Stream', value: 'Stream' } )) .addRoleOption(option => option.setName('role') .setDescription('Select a role to apply permissions to') .setRequired(true)) .setDefaultMemberPermissions(PermissionFlagsBits.Administrator), async execute(interaction) { const categoryId = interaction.options.getString('category'); const type = interaction.options.getString('type'); const permission = interaction.options.getString('permissions'); const role = interaction.options.getRole('role'); const guild = interaction.guild; const category = guild.channels.cache.get(categoryId); if (!category || category.type !== ChannelType.GuildCategory) { return interaction.reply({ content: 'Invalid category ID.', ephemeral: true }); } const validPermissions = { GuildText: ['ViewChannel', 'SendMessages', 'ManageMessages'], GuildVoice: ['Connect', 'Speak', 'MuteMembers', 'DeafenMembers', 'Stream'] }; if (!validPermissions[type].includes(permission)) { const embed = new EmbedBuilder() .setColor('#FF0000') .setTitle(`${emotes.warning} Invalid Permission`) .setDescription(`The permission **${permission}** is not valid for the selected channel type **${type}**.`); return interaction.reply({ embeds: [embed], ephemeral: true }); } const channels = category.children.cache.filter(channel => (type === 'GuildVoice' && channel.type === ChannelType.GuildVoice) || (type === 'GuildText' && channel.type === ChannelType.GuildText) ); if (!channels.size) { const embed2 = new EmbedBuilder() .setColor('#FF0000') .setTitle(`${emotes.warning} No Channels Found`) .setDescription(`No ${type.toLowerCase()} channels found in this category.`); return interaction.reply({ embeds: [embed2], ephemeral: true }); } for (const channel of channels.values()) { await channel.permissionOverwrites.edit(role, { [PermissionFlagsBits[permission]]: true }); } const embed3 = new EmbedBuilder() .setColor('#00FF00') .setTitle(`${emotes.check} Permissions Updated`) .setDescription(`Permission **${permission}** has been updated for role <@&${role.id}> in all ${type.toLowerCase()} channels in category **${category.name}**.`); interaction.reply({ embeds: [embed3], ephemeral: false }); } };
Editor is loading...
Leave a Comment