mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-01 08:20:08 +00:00
* fix: check new types idea * fix: type errors * fix: new style * fix: more cleanup * fix: more cleanup * fix: cleanup audit logs * fix: cleanup stickers * fix: cleanup integrations * fix: more cleanup * fix: organize into 1 place * fix: few errors * fix: some broken import fixes * fix: quite a lot of fixes across the board * fix: more fixes for broken imports * fix: more fixes for broken imports * fix: handler imports * fix: all remaining import errors * fix: more errors needing fixes * fix: clearing up transformers * fix: few moer types * fix: more cleanup of extra types * fix: fmt * fix: cleanup discordeno file * Nuke Base Types (#2102) * fix: cleanup snake stuff * convert camelCase to snake_case (#2103) * fix: add camelize * fix: finalize remaining errors * fix: imports in test Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import type { Bot } from "../../bot.ts";
|
|
import { Embed } from "../../transformers/embed.ts";
|
|
import { DiscordMessage } from "../../types/discord.ts";
|
|
import { AllowedMentions, FileContent, MessageComponents } from "../../types/discordeno.ts";
|
|
|
|
/** Send a webhook with webhook Id and webhook token */
|
|
export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: string, options: ExecuteWebhook) {
|
|
const allowedMentions = options.allowedMentions
|
|
? {
|
|
parse: options.allowedMentions.parse,
|
|
repliedUser: options.allowedMentions.repliedUser,
|
|
users: options.allowedMentions.users?.map((id) => id.toString()),
|
|
roles: options.allowedMentions.roles?.map((id) => id.toString()),
|
|
}
|
|
: { parse: [] };
|
|
|
|
const result = await bot.rest.runMethod<DiscordMessage>(
|
|
bot.rest,
|
|
"post",
|
|
`${bot.constants.endpoints.WEBHOOK(webhookId, webhookToken)}?wait=${options.wait ?? false}${
|
|
options.threadId ? `&thread_id=${options.threadId}` : ""
|
|
}`,
|
|
{
|
|
wait: options.wait,
|
|
thread_id: options.threadId,
|
|
content: options.content,
|
|
username: options.username,
|
|
avatar_url: options.avatarUrl,
|
|
tts: options.tts,
|
|
file: options.file,
|
|
embeds: options.embeds,
|
|
allowed_mentions: allowedMentions,
|
|
component: options.components,
|
|
},
|
|
);
|
|
if (!options.wait) return;
|
|
|
|
return bot.transformers.message(bot, result);
|
|
}
|
|
|
|
/** https://discord.com/developers/docs/resources/webhook#execute-webhook */
|
|
export interface ExecuteWebhook {
|
|
/** Waits for server confirmation of message send before response, and returns the created message body (defaults to `false`; when `false` a message that is not saved does not return an error) */
|
|
wait?: boolean;
|
|
/** Send a message to the specified thread within a webhook's channel. The thread will automatically be unarchived. */
|
|
threadId?: bigint;
|
|
/** The message contents (up to 2000 characters) */
|
|
content?: string;
|
|
/** Override the default username of the webhook */
|
|
username?: string;
|
|
/** Override the default avatar of the webhook */
|
|
avatarUrl?: string;
|
|
/** True if this is a TTS message */
|
|
tts?: boolean;
|
|
/** The contents of the file being sent */
|
|
file?: FileContent | FileContent[];
|
|
/** Embedded `rich` content */
|
|
embeds?: Embed[];
|
|
/** Allowed mentions for the message */
|
|
allowedMentions?: AllowedMentions;
|
|
/** the components to include with the message */
|
|
components?: MessageComponents;
|
|
}
|