diff --git a/src/commands/messages/alliaces/createEmbedv2.ts b/src/commands/messages/alliaces/createEmbedv2.ts index 5d28404..4444c09 100644 --- a/src/commands/messages/alliaces/createEmbedv2.ts +++ b/src/commands/messages/alliaces/createEmbedv2.ts @@ -2,6 +2,7 @@ import { CommandMessage } from "../../../core/types/commands"; // @ts-ignore import { ComponentType, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, Message, MessageFlags } from "discord.js"; import { replaceVars, isValidUrlOrVariable, listVariables } from "../../../core/lib/vars"; +import { patchMessageWithDisplay } from "../../../core/api/discordAPI"; /** * Botones de edición - VERSIÓN MEJORADA @@ -217,6 +218,11 @@ const renderPreview = async (blockState: any, member: any, guild: any) => { }; }; +// Helper para actualizar el editor vía REST y no filtrar display +const updateEditor = async (msg: any, data: any) => { + await patchMessageWithDisplay(msg.channelId, msg.id, data); +}; + export const command: CommandMessage = { name: "crear-embed", type: "message", @@ -269,10 +275,9 @@ export const command: CommandMessage = { await new Promise(resolve => setTimeout(resolve, 5000)); //@ts-ignore - await editorMessage.edit({ + await updateEditor(editorMessage, { content: null, flags: 4096, - // @ts-ignore - display (Display Components) display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -309,8 +314,7 @@ export const command: CommandMessage = { } } }); - await editorMessage.edit({ - // @ts-ignore + await updateEditor(editorMessage, { display: { type: 17, accent_color: blockState.color ?? null, @@ -490,8 +494,7 @@ export const command: CommandMessage = { } else if (b.customId === "delete_cover") { blockState.coverImage = null; await b.update({ content: "✅ Imagen de portada eliminada.", components: [] }); - await editorMessage.edit({ - // @ts-ignore + await updateEditor(editorMessage, { display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -603,8 +606,7 @@ export const command: CommandMessage = { await b.update({ content: "✅ Bloque movido abajo.", components: [] }); } - await editorMessage.edit({ - // @ts-ignore + await updateEditor(editorMessage, { display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -692,8 +694,7 @@ export const command: CommandMessage = { await sel.update({ content: "✅ Elemento eliminado.", components: [] }); } - await editorMessage.edit({ - // @ts-ignore + await updateEditor(editorMessage, { display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -785,8 +786,7 @@ export const command: CommandMessage = { blockState.components.splice(idx + 1, 0, duplicatedComponent); await sel.update({ content: "✅ Elemento duplicado.", components: [] }); - await editorMessage.edit({ - // @ts-ignore + await updateEditor(editorMessage, { display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -1044,7 +1044,7 @@ export const command: CommandMessage = { } else if (b.customId.startsWith('delete_link_button_')) { delete textComp.linkButton; await b.update({ content: '✅ Botón link eliminado.', components: [] }); - await editorMessage.edit({ components: [await renderPreview(blockState, message.member, message.guild), ...btns(false)] }); + await updateEditor(editorMessage, { components: [await renderPreview(blockState, message.member, message.guild), ...btns(false)] }); } }); } else { @@ -1091,8 +1091,7 @@ export const command: CommandMessage = { } } - await editorMessage.edit({ - // @ts-ignore + await updateEditor(editorMessage, { display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -1248,7 +1247,7 @@ export const command: CommandMessage = { try { const messageExists = await editorMessage.fetch().catch(() => null); if (!messageExists) return; - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -1286,7 +1285,7 @@ export const command: CommandMessage = { try { const messageExists = await editorMessage.fetch().catch(() => null); if (messageExists) { - await editorMessage.edit({ + await updateEditor(editorMessage, { // @ts-ignore display: { type: 17, diff --git a/src/commands/messages/alliaces/editEmbedv2.ts b/src/commands/messages/alliaces/editEmbedv2.ts index a2dbe15..7223f72 100644 --- a/src/commands/messages/alliaces/editEmbedv2.ts +++ b/src/commands/messages/alliaces/editEmbedv2.ts @@ -2,6 +2,7 @@ import { CommandMessage } from "../../../core/types/commands"; // @ts-ignore import { ComponentType, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, MessageFlags } from "discord.js"; import { replaceVars, isValidUrlOrVariable, listVariables } from "../../../core/lib/vars"; +import { patchMessageWithDisplay } from "../../../core/api/discordAPI"; // Botones de edición (máx 5 por fila) const btns = (disabled = false) => ([ @@ -104,6 +105,11 @@ const renderPreview = async (blockState: any, member: any, guild: any) => { return { type: 17, accent_color: blockState.color ?? null, components: previewComponents }; }; +// Helper para actualizar el editor vía REST y no filtrar display +const updateEditor = async (msg: any, data: any) => { + await patchMessageWithDisplay(msg.channelId, msg.id, data); +}; + export const command: CommandMessage = { name: "editar-embed", type: "message", @@ -151,10 +157,9 @@ export const command: CommandMessage = { await new Promise(r => setTimeout(r, 3000)); // @ts-ignore - await editorMessage.edit({ + await updateEditor(editorMessage, { content: null, flags: 4096, - // @ts-ignore - Display Components display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -174,7 +179,7 @@ export const command: CommandMessage = { where: { guildId_name: { guildId: message.guildId!, name: blockName } }, data: { config: blockState } }); - await editorMessage.edit({ + await updateEditor(editorMessage, { // @ts-ignore display: { type: 17, @@ -263,7 +268,7 @@ export const command: CommandMessage = { } else if (b.customId === 'delete_cover') { blockState.coverImage = null; await b.update({ content: '✅ Imagen de portada eliminada.', components: [] }); - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -316,7 +321,7 @@ export const command: CommandMessage = { } await b.update({ content: '✅ Bloque movido abajo.', components: [] }); } - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -354,7 +359,7 @@ export const command: CommandMessage = { blockState.components.splice(idx, 1); await sel.update({ content: '✅ Elemento eliminado.', components: [] }); } - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -408,7 +413,7 @@ export const command: CommandMessage = { const duplicatedComponent = JSON.parse(JSON.stringify(originalComponent)); blockState.components.splice(idx + 1, 0, duplicatedComponent); await sel.update({ content: '✅ Elemento duplicado.', components: [] }); - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -519,7 +524,7 @@ export const command: CommandMessage = { } else if (b.customId.startsWith('delete_link_button_')) { delete textComp.linkButton; await b.update({ content: '✅ Botón link eliminado.', components: [] }); - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -543,7 +548,7 @@ export const command: CommandMessage = { } } - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -626,7 +631,7 @@ export const command: CommandMessage = { try { const exists = await editorMessage.fetch().catch(() => null); if (!exists) return; - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: await renderPreview(blockState, message.member, message.guild), components: btns(false) }); @@ -643,7 +648,7 @@ export const command: CommandMessage = { try { const exists = await editorMessage.fetch().catch(() => null); if (exists) { - await editorMessage.edit({ // @ts-ignore + await updateEditor(editorMessage, { // @ts-ignore display: { type: 17, components: [{ type: 10, content: '⏰ Editor finalizado por inactividad.' }] }, components: [] }); diff --git a/src/core/api/discordAPI.ts b/src/core/api/discordAPI.ts index fc10b98..5eb48d4 100644 --- a/src/core/api/discordAPI.ts +++ b/src/core/api/discordAPI.ts @@ -3,6 +3,9 @@ import { REST } from "discord.js"; import { Routes } from "discord-api-types/v10"; import { commands } from "../loader"; +// Reutilizamos una instancia REST singleton +const rest = new REST({ version: '10' }).setToken(process.env.TOKEN ?? ""); + export async function registeringCommands(): Promise { const commandsToRegister: any[] = []; @@ -20,8 +23,6 @@ export async function registeringCommands(): Promise { } } - const rest = new REST().setToken(process.env.TOKEN ?? ""); - try { console.log(`🧹 Limpiando comandos antiguos/residuales...`); @@ -61,8 +62,6 @@ export async function registeringCommands(): Promise { * Función específica para eliminar TODOS los comandos slash (útil para limpieza) */ export async function clearAllCommands(): Promise { - const rest = new REST().setToken(process.env.TOKEN ?? ""); - try { console.log(`🧹 Eliminando TODOS los comandos slash...`); @@ -84,8 +83,6 @@ export async function clearAllCommands(): Promise { * Función para limpiar comandos globales (si los hay) */ export async function clearGlobalCommands(): Promise { - const rest = new REST().setToken(process.env.TOKEN ?? ""); - try { console.log(`🌍 Eliminando comandos globales...`); @@ -99,3 +96,8 @@ export async function clearGlobalCommands(): Promise { console.error("❌ Error eliminando comandos globales:", error); } } + +export async function patchMessageWithDisplay(channelId: string, messageId: string, data: any): Promise { + // data puede incluir: content, flags, display (container), components (action rows), etc. + await rest.patch(Routes.channelMessage(channelId, messageId), { body: data }); +}