DiscordFacade
ctx.libs.discord: fachada estilo discord.js sobre la API REST de Discord con el BOT del dominio (token guardado SOLO por el nucleo). SIN gateway ni
websocket (no existe en serverless): consultas y acciones bajo demanda; los eventos en vivo llegan por Interactions HTTP (hook DISCORD_INTERACTION).
Permisos del manifest (el admin los aprueba): OAUTH_SHARED:discord + grupos OAUTH_ACCOUNT:discord:bot-read (lectura), bot-write (mensajes, reacciones,
hilos, comandos) y bot-mod (expulsar, banear, roles, borrar mensajes y comandos; ademas el admin debe activar "Permitir moderación"). El nucleo solo
permite los servidores de "Servidores permitidos" (vacio = el servidor por defecto), aplica cuotas por hora y limites de tasa de Discord, y NUNCA devuelve
el token. Los IDs se validan como snowflakes (17-20 digitos) y los limites (mensajes <= 100, miembros <= 200) antes de llamar.
Las claves que no son de la fachada (me, myGuilds, webhook.post) siguen siendo las acciones OAuth de usuario ({ status, data }).
Firma
export interface DiscordFacade {
guilds: { list(opts?: { limit?: number; before?: string; after?: string; }): Promise<DiscordGuild[]>; fetch(guildId: string): Promise<DiscordGuildHandle>; };
channels: { listIn(guildId: string): Promise<DiscordChannel[]>; fetch(channelId: string): Promise<DiscordChannelHandle>; send(channelId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; };
messages: { send(channelId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; edit(channelId: string, messageId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; list(channelId: string, opts?: { limit?: number; before?: string; after?: string; around?: string; }): Promise<DiscordMessage[]>; fetch(channelId: string, messageId: string): Promise<DiscordMessage>; remove(channelId: string, messageId: string): Promise<true>; };
members: { list(guildId: string, opts?: { limit?: number; after?: string; }): Promise<DiscordMember[]>; fetch(guildId: string, userId: string): Promise<DiscordMember>; search(guildId: string, query: string, opts?: { limit?: number; }): Promise<DiscordMember[]>; kick(guildId: string, userId: string): Promise<true>; ban(guildId: string, userId: string, opts?: { deleteMessageSeconds?: number; }): Promise<true>; unban(guildId: string, userId: string): Promise<true>; addRole(guildId: string, userId: string, roleId: string): Promise<true>; removeRole(guildId: string, userId: string, roleId: string): Promise<true>; };
roles: { list(guildId: string): Promise<DiscordRole[]>; add(guildId: string, userId: string, roleId: string): Promise<true>; remove(guildId: string, userId: string, roleId: string): Promise<true>; };
threads: { active(guildId: string): Promise<DiscordChannel[]>; create(channelId: string, opts: { name: string; autoArchiveDuration?: 60 | 1440 | 4320 | 10080; messageId?: string; }): Promise<DiscordChannel>; send(threadId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; join(threadId: string): Promise<true>; };
reactions: { add(channelId: string, messageId: string, emoji: string): Promise<true>; remove(channelId: string, messageId: string, emoji: string): Promise<true>; list(channelId: string, messageId: string, emoji: string, opts?: { limit?: number; after?: string; }): Promise<DiscordUser[]>; };
webhooks: { list(channelId: string): Promise<DiscordWebhook[]>; };
commands: { list(opts?: { guildId?: string; }): Promise<DiscordCommand[]>; register(command: DiscordCommandInput, opts?: { guildId?: string; }): Promise<DiscordCommand>; remove(commandId: string, opts?: { guildId?: string; }): Promise<true>; };
users: { fetch(userId: string): Promise<DiscordUser>; };
escapeMentions(text: string): string;
escapeMarkdown(text: string): string;
status(): Promise<{ configured: boolean; guilds: number; moderation: boolean; }>;
}Miembros (13)
| Nombre | Tipo | Descripción |
|---|---|---|
| guildsobligatorio | { list(opts?: { limit?: number; before?: string; after?: string; }): Promise<DiscordGuild[]>; fetch(guildId: string): Promise<DiscordGuildHandle>; } | Sin descripción. |
| channelsobligatorio | { listIn(guildId: string): Promise<DiscordChannel[]>; fetch(channelId: string): Promise<DiscordChannelHandle>; send(channelId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; } | Sin descripción. |
| messagesobligatorio | { send(channelId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; edit(channelId: string, messageId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; list(channelId: string, opts?: { limit?: number; before?: string; after?: string; around?: string; }): Promise<DiscordMessage[]>; fetch(channelId: string, messageId: string): Promise<DiscordMessage>; remove(channelId: string, messageId: string): Promise<true>; } | Sin descripción. |
| membersobligatorio | { list(guildId: string, opts?: { limit?: number; after?: string; }): Promise<DiscordMember[]>; fetch(guildId: string, userId: string): Promise<DiscordMember>; search(guildId: string, query: string, opts?: { limit?: number; }): Promise<DiscordMember[]>; kick(guildId: string, userId: string): Promise<true>; ban(guildId: string, userId: string, opts?: { deleteMessageSeconds?: number; }): Promise<true>; unban(guildId: string, userId: string): Promise<true>; addRole(guildId: string, userId: string, roleId: string): Promise<true>; removeRole(guildId: string, userId: string, roleId: string): Promise<true>; } | Sin descripción. |
| rolesobligatorio | { list(guildId: string): Promise<DiscordRole[]>; add(guildId: string, userId: string, roleId: string): Promise<true>; remove(guildId: string, userId: string, roleId: string): Promise<true>; } | Sin descripción. |
| threadsobligatorio | { active(guildId: string): Promise<DiscordChannel[]>; create(channelId: string, opts: { name: string; autoArchiveDuration?: 60 | 1440 | 4320 | 10080; messageId?: string; }): Promise<DiscordChannel>; send(threadId: string, message: string | DiscordMessageInput): Promise<DiscordMessage>; join(threadId: string): Promise<true>; } | Sin descripción. |
| reactionsobligatorio | { add(channelId: string, messageId: string, emoji: string): Promise<true>; remove(channelId: string, messageId: string, emoji: string): Promise<true>; list(channelId: string, messageId: string, emoji: string, opts?: { limit?: number; after?: string; }): Promise<DiscordUser[]>; } | Sin descripción. |
| webhooksobligatorio | { list(channelId: string): Promise<DiscordWebhook[]>; } | Webhooks de un canal (solo lectura, SIN token). |
| commandsobligatorio | { list(opts?: { guildId?: string; }): Promise<DiscordCommand[]>; register(command: DiscordCommandInput, opts?: { guildId?: string; }): Promise<DiscordCommand>; remove(commandId: string, opts?: { guildId?: string; }): Promise<true>; } | Comandos de la aplicacion (globales; con |
| usersobligatorio | { fetch(userId: string): Promise<DiscordUser>; } | Sin descripción. |
| escapeMentions | escapeMentions(text: string): string | Escapa @everyone/@here (espacio de ancho cero). |
| escapeMarkdown | escapeMarkdown(text: string): string | Escapa los caracteres de Markdown de Discord. |
| status | status(): Promise<{ configured: boolean; guilds: number; moderation: boolean; }> | Estado del bot (sin valores sensibles): token guardado, servidores permitidos y si la moderacion esta activada. |
Ejemplos
const guild = await ctx.libs.discord.guilds.fetch("123456789012345678");
const channels = await guild.channels.list();
const sent = await ctx.libs.discord.channels.send(channels[0].id, { content: "Nuevo correo importante", embeds: [{ title: "Asunto", description: "…" }] });
const last = await ctx.libs.discord.messages.list(channels[0].id, { limit: 20 });
await ctx.libs.discord.reactions.add(channels[0].id, sent.id, "👍");
const thread = await ctx.libs.discord.threads.create(channels[0].id, { name: "Seguimiento", messageId: sent.id });
await ctx.libs.discord.threads.send(thread.id, "Primer mensaje del hilo");
await ctx.libs.discord.commands.register({ name: "estado", description: "Estado del buzón" }); // global; con { guildId } solo ese servidorUsado en / Referenciado por
Fuente: bloomx-extensions/_shared/sdk/ctx.d.ts:700 · ctx.d.ts