import { ApplicationCommandOptionType, Attachment, Colors, CommandInteraction, EmbedBuilder, MessageFlags, TextChannel, } from "discord.js"; import { Discord, Slash, SlashOption } from "discordx"; import db from "../db"; import { confessTable } from "../db/schema"; import { eq } from "drizzle-orm"; @Discord() export class Confession { @Slash({ name: "confess-setup", description: "setup confessions" }) async confessSetup( @SlashOption({ name: "log_channel", description: "channel to send logs", required: true, type: ApplicationCommandOptionType.Channel, }) channel: TextChannel, inter: CommandInteraction, ) { if (inter.guild?.ownerId != inter.user.id) { return inter.reply("you aren't the owner silly!"); } await db.insert(confessTable).values({ guild: inter.guildId!, channel: channel.id, }); await inter.reply("confess setup done!"); } @Slash({ name: "confess", description: "confessions are LOGGED for moderation purposes.", }) async confess( @SlashOption({ name: "message", description: "message to confess", required: true, type: ApplicationCommandOptionType.String, }) message: string, @SlashOption({ name: "attachment", description: "submit an image attachment with the message :3", required: false, type: ApplicationCommandOptionType.Attachment, }) attachment: Attachment, inter: CommandInteraction, ) { const embed = new EmbedBuilder() .setTitle("A Confession!") .setDescription(message) .setFooter({ text: "Confessions" }) .setColor(Colors.DarkRed); const logEmbed = new EmbedBuilder() .setTitle(`Confession Log from ${inter.user.username}`) .setDescription(message) .setFooter({ text: "Confession Log" }); if (attachment) { embed.setImage(attachment.url); logEmbed.setImage(attachment.url); } const channelRes = await db .select() .from(confessTable) .where(eq(confessTable.guild, inter.guildId!)); const channel = inter.client.channels.cache.get( channelRes[0].channel, ) as TextChannel; await (inter.channel as TextChannel).send({ embeds: [embed] }); await inter.reply({ content: "Confession Sent", flags: MessageFlags.Ephemeral, }); await channel.send({ embeds: [logEmbed] }); } }