From 43cee9eeb7b1d8c7356e8f0e92031d8592014417 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 8 Nov 2025 10:43:19 +0000 Subject: [PATCH] Create /unlink command to disconnect Discord account cgen-504dd52ffd5d46f198e36ae3dbd51c46 --- discord-bot/commands/unlink.js | 72 ++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 discord-bot/commands/unlink.js diff --git a/discord-bot/commands/unlink.js b/discord-bot/commands/unlink.js new file mode 100644 index 00000000..7c88dab8 --- /dev/null +++ b/discord-bot/commands/unlink.js @@ -0,0 +1,72 @@ +const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); + +module.exports = { + data: new SlashCommandBuilder() + .setName('unlink') + .setDescription('Unlink your Discord account from AeThex'), + + async execute(interaction, supabase) { + await interaction.deferReply({ ephemeral: true }); + + try { + const { data: link } = await supabase + .from('discord_links') + .select('*') + .eq('discord_id', interaction.user.id) + .single(); + + if (!link) { + const embed = new EmbedBuilder() + .setColor(0xFF6B6B) + .setTitle('â„šī¸ Not Linked') + .setDescription('Your Discord account is not linked to AeThex.'); + + return await interaction.editReply({ embeds: [embed] }); + } + + // Delete the link + await supabase + .from('discord_links') + .delete() + .eq('discord_id', interaction.user.id); + + // Remove Discord roles from user + const guild = interaction.guild; + const member = await guild.members.fetch(interaction.user.id); + + // Find and remove all AeThex-related roles + const rolesToRemove = member.roles.cache.filter(role => + role.name.includes('Labs') || + role.name.includes('GameForge') || + role.name.includes('Corp') || + role.name.includes('Foundation') || + role.name.includes('Dev-Link') || + role.name.includes('Premium') || + role.name.includes('Creator') + ); + + for (const [, role] of rolesToRemove) { + try { + await member.roles.remove(role); + } catch (e) { + console.warn(`Could not remove role ${role.name}`); + } + } + + const embed = new EmbedBuilder() + .setColor(0x00FF00) + .setTitle('✅ Account Unlinked') + .setDescription('Your Discord account has been unlinked from AeThex.\nAll associated roles have been removed.'); + + await interaction.editReply({ embeds: [embed] }); + } catch (error) { + console.error('Unlink command error:', error); + const embed = new EmbedBuilder() + .setColor(0xFF0000) + .setTitle('❌ Error') + .setDescription('Failed to unlink account. Please try again.'); + + await interaction.editReply({ embeds: [embed] }); + } + }, +};