Files
discordeno/helpers/webhooks/editWebhook.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.3 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";
/**
* Edits a webhook.
*
* @param bot - The bot instance to use to make the request.
* @param webhookId - The ID of the webhook to edit.
* @returns An instance of the edited {@link Webhook}.
*
* @remarks
* Requires the `MANAGE_WEBHOOKS` permission.
*
* Fires a _Webhooks Update_ gateway event.
*
* @see {@link https://discord.com/developers/docs/resources/webhook#edit-webhook}
*/
export async function editWebhook(bot: Bot, webhookId: bigint, options: ModifyWebhook): Promise<Webhook> {
const result = await bot.rest.runMethod<DiscordWebhook>(
bot.rest,
"PATCH",
bot.constants.routes.WEBHOOK_ID(webhookId),
{
name: options.name,
avatar: options.avatar,
channel_id: options.channelId,
reason: options.reason,
},
);
return bot.transformers.webhook(bot, result);
}
export interface ModifyWebhook extends WithReason {
/** The default name of the webhook */
name?: string;
/** Image for the default webhook avatar */
avatar?: bigint | null;
/** The new channel id this webhook should be moved to */
channelId?: bigint;
}