import { ChannelType, MessageFlags, PermissionFlagsBits, SlashCommandSubcommandBuilder } from "discord.js"; import { Command, requirePermission } from "@voidy/framework"; import { GuildConfig, type IGuildConfig } from "../schemas/GuildConfig"; export default new Command({ id: "guild.setup", use: [requirePermission(PermissionFlagsBits.ManageGuild)], data: new SlashCommandSubcommandBuilder() .setName("setup") .setDescription("Set up guild configuration (logging, welcome, auto-roles).") .addChannelOption((option) => option .setName("log_channel") .setDescription("Channel for member join/leave logging.") .addChannelTypes(ChannelType.GuildText) .setRequired(true), ) .addChannelOption((option) => option .setName("welcome_channel") .setDescription("Channel for welcome messages.") .addChannelTypes(ChannelType.GuildText), ) .addRoleOption((option) => option.setName("member_role").setDescription("Auto-role assigned to new members."), ) .addRoleOption((option) => option.setName("bot_role").setDescription("Auto-role assigned to new bots."), ), execute: async ({ interaction, client }) => { const logChannel = interaction.options.getChannel("log_channel", true); const welcomeChannel = interaction.options.getChannel("welcome_channel"); const memberRole = interaction.options.getRole("member_role"); const botRole = interaction.options.getRole("bot_role"); const update: Record = { "logging.channelId": logChannel.id, }; if (welcomeChannel) update["welcome.channelId"] = welcomeChannel.id; if (memberRole) update["autoRoles.memberRoleId"] = memberRole.id; if (botRole) update["autoRoles.botRoleId"] = botRole.id; const doc = await GuildConfig.findOneAndUpdate( { guildId: interaction.guildId }, { $set: update }, { upsert: true, new: true }, ); const cache = client.data.get("guildConfig") as Map | undefined; if (cache && interaction.guildId) cache.set(interaction.guildId, doc.toObject()); const lines = [`Logging channel set to <#${logChannel.id}>`]; if (welcomeChannel) lines.push(`Welcome channel set to <#${welcomeChannel.id}>`); if (memberRole) lines.push(`Member auto-role set to <@&${memberRole.id}>`); if (botRole) lines.push(`Bot auto-role set to <@&${botRole.id}>`); await interaction.reply({ content: `Guild configuration updated:\n${lines.join("\n")}`, flags: [MessageFlags.Ephemeral], }); }, });