UNPKG

dressed

Version:

A sleek, serverless-ready Discord bot framework.

190 lines 6.3 kB
import { Routes } from "discord-api-types/v10"; import { callDiscord } from "../utils/call-discord.js"; /** * Lists the messages in a channel. * @param channel The channel to get the messages from * @param options Optional parameters for the request */ export async function listMessages(channel, options) { const res = await callDiscord(Routes.channelMessages(channel), { method: "GET", params: options, }); return res.json(); } /** * Retrieves a specific message in the channel. * @param channel The channel to get the message from * @param message The snowflake of the message to get */ export async function getMessage(channel, message) { const res = await callDiscord(Routes.channelMessage(channel, message), { method: "GET", }); return res.json(); } /** * Post a message to a guild text or DM channel. * @param channel The channel to post the message in * @param data The message data */ export async function createMessage(channel, data) { if (typeof data === "string") { data = { content: data }; } const res = await callDiscord(Routes.channelMessages(channel), { method: "POST", body: data, }); return res.json(); } /** * Crosspost a message in an Announcement Channel to following channels. * @param channel The channel to post from * @param message The snowflake of the message to crosspost */ export async function crosspostMessage(channel, message) { const res = await callDiscord(Routes.channelMessageCrosspost(channel, message), { method: "POST", }); return res.json(); } /** * Adds a reaction to a message. * @param channel The channel to add the reaction in * @param message The message to add the reaction to * @param emoji The emoji to react with */ export async function createReaction(channel, message, emoji) { await callDiscord(Routes.channelMessageOwnReaction(channel, message, emoji), { method: "PUT", }); } /** * Deletes a reaction from a message. * @param channel The channel to delete the reaction in * @param message The message to delete the reaction from * @param emoji The emoji to delete * @param user The user to delete the reaction for (defaults to self) */ export async function deleteReaction(channel, message, emoji, user) { await callDiscord(Routes.channelMessageUserReaction(channel, message, emoji, user !== null && user !== void 0 ? user : "@me"), { method: "DELETE", }); } /** * Get a list of users that reacted with this emoji. * @param channel The channel to get the reaction in * @param message The message to get the reaction from * @param emoji The emoji to list * @param options Optional parameters for the request */ export async function listReactions(channel, message, emoji, options) { const res = await callDiscord(Routes.channelMessageReaction(channel, message, emoji), { method: "GET", params: options, }); return res.json(); } /** * Deletes all reactions on a message. * @param channel The channel to delete the reactions in * @param message The message to delete the reactions from */ export async function deleteAllReactions(channel, message) { await callDiscord(Routes.channelMessageAllReactions(channel, message), { method: "DELETE", }); } /** * Deletes all reactions of a specific emoji on a message. * @param channel The channel to delete the reactions in * @param message The message to delete the reactions from * @param emoji The emoji to delete */ export async function deleteAllEmojiReactions(channel, message, emoji) { await callDiscord(Routes.channelMessageReaction(channel, message, encodeURIComponent(emoji)), { method: "DELETE", }); } /** * Edit a previously sent message. * @param channel The channel to edit the message in * @param message The snowflake of the message to edit * @param data The new message data */ export async function editMessage(channel, message, data) { if (typeof data === "string") { data = { content: data }; } const res = await callDiscord(Routes.channelMessage(channel, message), { method: "PATCH", body: data, }); return res.json(); } /** * Delete a message. If operating on a guild channel and trying to delete a message that was not sent by the current user, this endpoint requires the `MANAGE_MESSAGES` permission. * @param channel The channel to delete the message from * @param message The snowflake of the message to delete */ export async function deleteMessage(channel, message) { await callDiscord(Routes.channelMessage(channel, message), { method: "DELETE", }); } /** * Delete multiple messages in a single request. * @param channel The channel to delete messages from * @param messages An array of snowflakes */ export async function bulkDelete(channel, messages) { await callDiscord(Routes.channelBulkDelete(channel), { method: "DELETE", body: { messages }, }); } /** * Returns all pinned messages in the channel. * @param channel The channel to find the pins for * @deprecated Use `listChannelPins` */ export async function listPins(channel) { const res = await callDiscord(Routes.channelPins(channel), { method: "GET", }); return res.json(); } /** * Retrieves the list of pins in a channel. * @param channel The channel to find the pins for * @param options Optional parameters for the request */ export async function listChannelPins(channel, options) { const res = await callDiscord(Routes.channelMessagesPins(channel), { method: "GET", params: options, }); return res.json(); } /** * Pin a message in a channel. * @param channel The channel to pin the message in * @param message The message to pin */ export async function createPin(channel, message) { await callDiscord(Routes.channelMessagesPin(channel, message), { method: "PUT", }); } /** * Unpin a message in a channel. * @param channel The channel to unpin the message in * @param message The message to unpin */ export async function deletePin(channel, message) { await callDiscord(Routes.channelMessagesPin(channel, message), { method: "DELETE", }); } //# sourceMappingURL=messages.js.map