Files
discordeno/helpers/webhooks/createWebhook.ts
LTS20050703 16f109ad43 chore: WithReason type cleanup (#2449)
* type WithReason<T> = T & { reason?: string }

* deno fmt (1.25.2)

* WithReason: jsdoc comments for reason

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>

* deno fmt

* types: WithReason type -> WithReason interface

* Fix: Some helpers missing support for reason

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
2022-09-12 08:52:03 -05:00

44 lines
1.4 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { WithReason } from "../../mod.ts";
import { Webhook } from "../../transformers/webhook.ts";
import { DiscordWebhook } from "../../types/discord.ts";
/**
* Creates a webhook.
*
* @param bot - The bot instance to use to make the request.
* @param channelId - The ID of the channel to create the webhook in.
* @param options - The parameters for the creation of the webhook.
* @returns An instance of the created {@link Webhook}.
*
* @remarks
* Requires the `MANAGE_WEBHOOKS` permission.
*
* ⚠️ The webhook name must not contain the string 'clyde' (case-insensitive).
*
* Fires a _Webhooks Update_ gateway event.
*
* @see {@link https://discord.com/developers/docs/resources/webhook#create-webhook}
*/
export async function createWebhook(bot: Bot, channelId: bigint, options: CreateWebhook): Promise<Webhook> {
const result = await bot.rest.runMethod<DiscordWebhook>(
bot.rest,
"POST",
bot.constants.routes.CHANNEL_WEBHOOKS(channelId),
{
name: options.name,
avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined,
reason: options.reason,
},
);
return bot.transformers.webhook(bot, result);
}
export interface CreateWebhook extends WithReason {
/** Name of the webhook (1-80 characters) */
name: string;
/** Image url for the default webhook avatar */
avatar?: string | null;
}