revert code
This commit is contained in:
@@ -2,7 +2,6 @@ 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
|
||||
@@ -218,9 +217,17 @@ const renderPreview = async (blockState: any, member: any, guild: any) => {
|
||||
};
|
||||
};
|
||||
|
||||
// Helper para actualizar el editor vía REST y no filtrar display
|
||||
// Helper para actualizar el editor combinando Display Container dentro de components
|
||||
const updateEditor = async (msg: any, data: any) => {
|
||||
await patchMessageWithDisplay(msg.channelId, msg.id, data);
|
||||
const container = data?.display;
|
||||
const rows = Array.isArray(data?.components) ? data.components : [];
|
||||
const components = container ? [container, ...rows] : rows;
|
||||
const payload: any = { ...data };
|
||||
delete payload.display;
|
||||
payload.components = components;
|
||||
// Si no se pasa flags explícitos, usamos 32768 como en tu entorno
|
||||
if (payload.flags === undefined) payload.flags = 32768;
|
||||
await msg.edit(payload);
|
||||
};
|
||||
|
||||
export const command: CommandMessage = {
|
||||
@@ -277,7 +284,7 @@ export const command: CommandMessage = {
|
||||
//@ts-ignore
|
||||
await updateEditor(editorMessage, {
|
||||
content: null,
|
||||
flags: 4096,
|
||||
flags: 32768,
|
||||
display: await renderPreview(blockState, message.member, message.guild),
|
||||
components: btns(false)
|
||||
});
|
||||
|
||||
@@ -2,7 +2,6 @@ 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) => ([
|
||||
@@ -105,9 +104,16 @@ 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
|
||||
// Helper para actualizar el editor combinando Display Container dentro de components
|
||||
const updateEditor = async (msg: any, data: any) => {
|
||||
await patchMessageWithDisplay(msg.channelId, msg.id, data);
|
||||
const container = data?.display;
|
||||
const rows = Array.isArray(data?.components) ? data.components : [];
|
||||
const components = container ? [container, ...rows] : rows;
|
||||
const payload: any = { ...data };
|
||||
delete payload.display;
|
||||
payload.components = components;
|
||||
if (payload.flags === undefined) payload.flags = 32768; // según formato real en tu entorno
|
||||
await msg.edit(payload);
|
||||
};
|
||||
|
||||
export const command: CommandMessage = {
|
||||
@@ -159,7 +165,7 @@ export const command: CommandMessage = {
|
||||
// @ts-ignore
|
||||
await updateEditor(editorMessage, {
|
||||
content: null,
|
||||
flags: 4096,
|
||||
flags: 32768,
|
||||
display: await renderPreview(blockState, message.member, message.guild),
|
||||
components: btns(false)
|
||||
});
|
||||
|
||||
@@ -97,28 +97,3 @@ export async function clearGlobalCommands(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
export async function patchMessageWithDisplay(channelId: string, messageId: string, data: any): Promise<void> {
|
||||
try {
|
||||
// Validación mínima para ayudar a depurar
|
||||
const dbg = {
|
||||
hasDisplay: !!data?.display,
|
||||
displayType: data?.display?.type,
|
||||
compCount: Array.isArray(data?.display?.components) ? data.display.components.length : undefined,
|
||||
hasComponents: Array.isArray(data?.components),
|
||||
};
|
||||
// eslint-disable-next-line no-console
|
||||
if (!dbg.hasDisplay) console.warn('[patchMessageWithDisplay] Enviando PATCH sin display. data.keys=', Object.keys(data || {}));
|
||||
await rest.patch(Routes.channelMessage(channelId, messageId), { body: data });
|
||||
} catch (error: any) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('[patchMessageWithDisplay] Error PATCH mensaje', {
|
||||
channelId,
|
||||
messageId,
|
||||
status: error?.status,
|
||||
code: error?.code,
|
||||
message: error?.message,
|
||||
rawError: error?.rawError,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user