UNPKG

dressed

Version:

A sleek, serverless-ready Discord bot framework.

132 lines 3.93 kB
import { Routes } from "discord-api-types/v10"; import { callDiscord } from "../utils/call-discord.js"; /** * Creates a new webhook. * @param channel The channel to create the webhooks on * @param data The data for the new webhook */ export async function createWebhook(channel, data) { const res = await callDiscord(Routes.webhook(channel), { method: "POST", body: data, }); return res.json(); } /** * Returns a list of channel webhook objects. * @param channel The channel to get the webhooks from */ export async function listChannelWebhooks(channel) { const res = await callDiscord(Routes.channelWebhooks(channel), { method: "GET", }); return res.json(); } /** * Returns a list of guild webhook objects. * @param guild The guild to get the webhooks from */ export async function listGuildWebhooks(guild) { const res = await callDiscord(Routes.guildWebhooks(guild), { method: "GET", }); return res.json(); } /** * Returns the new webhook object for the given id. * @param webhook The webhook to get * @param token The webhook token */ export async function getWebhook(webhook, token) { const res = await callDiscord(Routes.webhook(webhook, token), { method: "GET", }); return res.json(); } /** * Modify a webhook. * @param webhook The webhook to modify * @param data The new data for the webhook * @param token The webhook token */ export async function modifyWebhook(webhook, data, token) { const res = await callDiscord(Routes.webhook(webhook, token), { method: "PATCH", body: data, }); return res.json(); } /** * Delete a webhook permanently. * @param webhook The webhook to delete * @param token The webhook token */ export async function deleteWebhook(webhook, token) { await callDiscord(Routes.webhook(webhook, token), { method: "DELETE", }); } /** * Execute a webhook. * @param webhook The webhook to use * @param token The webhook token * @param data The message data * @param options Optional parameters for the request */ export async function executeWebhook(webhook, token, data, options) { if (typeof data === "string") { data = { content: data }; } const res = await callDiscord(Routes.webhook(webhook, token), { method: "POST", body: data, params: options, }); return res.json(); } /** * Returns a previously-sent webhook message from the same token. * @param webhook The webhook to use * @param token The webhook token * @param message The message to get * @param options Optional parameters for the request */ export async function getWebhookMessage(webhook, token, message, options) { const res = await callDiscord(Routes.webhookMessage(webhook, token, message), { method: "GET", params: options, }); return res.json(); } /** * Edits a previously-sent webhook message from the same token. * @param webhook The webhook to use * @param token The webhook token * @param message The message to edit * @param data The new message data * @param options Optional parameters for the request */ export async function editWebhookMessage(webhook, token, message, data, options) { if (typeof data === "string") { data = { content: data }; } const res = await callDiscord(Routes.webhookMessage(webhook, token, message), { method: "PATCH", body: data, params: options, }); return res.json(); } /** * Deletes a message that was created by the webhook. * @param webhook The webhook to use * @param token The webhook token * @param message The message to delete */ export async function deleteWebhookMessage(webhook, token, message, options) { await callDiscord(Routes.webhookMessage(webhook, token, message), { method: "DELETE", params: options, }); } //# sourceMappingURL=webhooks.js.map