UNPKG

dressed

Version:

A sleek, serverless-ready Discord bot framework.

1,004 lines 99.1 kB
import { ChannelType, Routes, } from "discord-api-types/v10"; import { callDiscord } from "../utils/call-discord.js"; import { botEnv } from "../utils/env.js"; /** * Fetch all of the global commands for your application. * @warn The objects returned by this endpoint may be augmented with [additional fields if localization is active](https://discord.com/developers/docs/interactions/application-commands#retrieving-localized-commands). * @see https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands */ export async function listGlobalCommands(params, $req) { var _a, _b; const res = await callDiscord(Routes.applicationCommands((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "GET", params, }, $req); return res.json(); } /** * Create a new global command. * @warn Creating a command with the same name as an existing command for your application will overwrite the old command. * @see https://discord.com/developers/docs/interactions/application-commands#create-global-application-command */ export async function createGlobalCommand(data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationCommands((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "POST", body: data, }, $req); return res.json(); } /** * Fetch a global command for your application. * @see https://discord.com/developers/docs/interactions/application-commands#get-global-application-command */ export async function getGlobalCommand(commandId, $req) { var _a, _b; const res = await callDiscord(Routes.applicationCommand((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, commandId), { method: "GET", }, $req); return res.json(); } /** * Edit a global command. * @see https://discord.com/developers/docs/interactions/application-commands#edit-global-application-command */ export async function modifyGlobalCommand(commandId, data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationCommand((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, commandId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Deletes a global command. * @see https://discord.com/developers/docs/interactions/application-commands#delete-global-application-command */ export async function deleteGlobalCommand(commandId, $req) { var _a, _b; const _res = await callDiscord(Routes.applicationCommand((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, commandId), { method: "DELETE", }, $req); } /** * Takes a list of application commands, overwriting the existing global command list for this application. * @danger This will overwrite all types of application commands: slash commands, user commands, and message commands. * @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands */ export async function bulkOverwriteGlobalCommands(data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationCommands((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "PUT", body: data, }, $req); return res.json(); } /** * Fetch all of the guild commands for your application for a specific guild. * @warn The objects returned by this endpoint may be augmented with [additional fields if localization is active](https://discord.com/developers/docs/interactions/application-commands#retrieving-localized-commands). * @see https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands */ export async function listGuildCommands(guildId, params, $req) { var _a, _b; const res = await callDiscord(Routes.applicationGuildCommands((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId), { method: "GET", params, }, $req); return res.json(); } /** * Create a new guild command. New guild commands will be available in the guild immediately. * @danger Creating a command with the same name as an existing command for your application will overwrite the old command. * @see https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command */ export async function createGuildCommand(guildId, data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationGuildCommands((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId), { method: "POST", body: data, }, $req); return res.json(); } /** * Fetch a guild command for your application. * @see https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command */ export async function getGuildCommand(guildId, commandId, $req) { var _a, _b; const res = await callDiscord(Routes.applicationGuildCommand((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId, commandId), { method: "GET", }, $req); return res.json(); } /** * Edit a guild command. Updates for guild commands will be available immediately. * @see https://discord.com/developers/docs/interactions/application-commands#edit-guild-application-command */ export async function modifyGuildCommand(guildId, commandId, data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationGuildCommand((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId, commandId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Delete a guild command. * @see https://discord.com/developers/docs/interactions/application-commands#delete-guild-application-command */ export async function deleteGuildCommand(guildId, commandId, $req) { var _a, _b; const _res = await callDiscord(Routes.applicationGuildCommand((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId, commandId), { method: "DELETE", }, $req); } /** * Takes a list of application commands, overwriting the existing command list for this application for the targeted guild. * @danger This will overwrite **all** types of application commands: slash commands, user commands, and message commands. * @see https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands */ export async function bulkOverwriteGuildCommands(guildId, data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationGuildCommands((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId), { method: "PUT", body: data, }, $req); return res.json(); } /** * Fetches permissions for all commands for your application in a guild. * @see https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command-permissions */ export async function listGuildCommandsPermissions(guildId, $req) { var _a, _b; const res = await callDiscord(Routes.guildApplicationCommandsPermissions((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId), { method: "GET", }, $req); return res.json(); } /** * Fetches permissions for a specific command for your application in a guild. * @see https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions */ export async function getGuildCommandPermissions(guildId, commandId, $req) { var _a, _b; const res = await callDiscord(Routes.applicationCommandPermissions((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId, commandId), { method: "GET", }, $req); return res.json(); } /** * Edits command permissions for a specific command for your application in a guild. * @warn This endpoint will overwrite existing permissions for the command in that guild * @warn Deleting or renaming a command will permanently delete all permissions for the command * @see https://discord.com/developers/docs/interactions/application-commands#edit-application-command-permissions */ export async function modifyGuildCommandPermissions(guildId, commandId, data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationCommandPermissions((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, guildId, commandId), { method: "PUT", body: data, }, $req); return res.json(); } /** * Returns a list of [application role connection metadata](https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object) objects for the given application. * @see https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records */ export async function listAppRoleConnectionMetadata($req) { var _a, _b; const res = await callDiscord(Routes.applicationRoleConnectionMetadata((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "GET", }, $req); return res.json(); } /** * Updates and returns a list of [application role connection metadata](https://discord.com/developers/docs/resources/application-role-connection-metadata#application-role-connection-metadata-object) objects for the given application. * @info An application can have a maximum of 5 metadata records. * @see https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records */ export async function modifyAppRoleConnectionMetadata($req) { var _a, _b; const res = await callDiscord(Routes.applicationRoleConnectionMetadata((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "PUT", }, $req); return res.json(); } /** * Returns the [application](https://discord.com/developers/docs/resources/application#application-object) object associated with the requesting bot user. * @see https://discord.com/developers/docs/resources/application#get-current-application */ export async function getApp($req) { const res = await callDiscord(Routes.currentApplication(), { method: "GET", }, $req); return res.json(); } /** * Edit properties of the app associated with the requesting bot user. Only properties that are passed will be updated. * @see https://discord.com/developers/docs/resources/application#edit-current-application */ export async function modifyApp(data, $req) { const res = await callDiscord(Routes.currentApplication(), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Returns an [audit log](https://discord.com/developers/docs/resources/audit-log#audit-log-object) object for the guild. * @info Requires the [`VIEW_AUDIT_LOG`](https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags) permission. * @see https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log */ export async function getAuditLog(guildId, params, $req) { const res = await callDiscord(Routes.guildAuditLog(guildId), { method: "GET", params, }, $req); return res.json(); } /** * Get a list of all rules currently configured for the guild. * @info This endpoint requires the `MANAGE_GUILD` [permission](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-permission-requirements). * @see https://discord.com/developers/docs/resources/auto-moderation#list-auto-moderation-rules-for-guild */ export async function listAutomodRules(guildId, $req) { const res = await callDiscord(Routes.guildAutoModerationRules(guildId), { method: "GET", }, $req); return res.json(); } /** * Get a single rule. * @info This endpoint requires the `MANAGE_GUILD` [permission](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-permission-requirements). * @see https://discord.com/developers/docs/resources/auto-moderation#get-auto-moderation-rule */ export async function getAutomodRule(guildId, ruleId, $req) { const res = await callDiscord(Routes.guildAutoModerationRule(guildId, ruleId), { method: "GET", }, $req); return res.json(); } /** * Create a new rule. * @info This endpoint requires the `MANAGE_GUILD` [permission](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-permission-requirements). * @see https://discord.com/developers/docs/resources/auto-moderation#create-auto-moderation-rule */ export async function createAutomodRule(guildId, data, $req) { const res = await callDiscord(Routes.guildAutoModerationRules(guildId), { method: "POST", body: data, }, $req); return res.json(); } /** * Modify an existing rule. * @info This endpoint requires the `MANAGE_GUILD` [permission](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-permission-requirements). * @see https://discord.com/developers/docs/resources/auto-moderation#modify-auto-moderation-rule */ export async function modifyAutomodRule(guildId, ruleId, data, $req) { const res = await callDiscord(Routes.guildAutoModerationRule(guildId, ruleId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Delete a rule. * @info This endpoint requires the `MANAGE_GUILD` [permission](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-permission-requirements). * @see https://discord.com/developers/docs/resources/auto-moderation#delete-auto-moderation-rule */ export async function deleteAutomodRule(guildId, ruleId, $req) { const _res = await callDiscord(Routes.guildAutoModerationRule(guildId, ruleId), { method: "DELETE", }, $req); } /** * Get a channel by ID. * @see https://discord.com/developers/docs/resources/channel#get-channel */ export async function getChannel(channelId, $req) { const res = await callDiscord(Routes.channel(channelId), { method: "GET", }, $req); return res.json(); } /** * Update a channel's settings. * @see https://discord.com/developers/docs/resources/channel#modify-channel */ export async function modifyChannel(channelId, data, $req) { const res = await callDiscord(Routes.channel(channelId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Delete a channel, or close a private message. * @info Requires the `MANAGE_CHANNELS` permission for the guild, or `MANAGE_THREADS` if the channel is a thread. * @info For Community guilds, the Rules or Guidelines channel and the Community Updates channel cannot be deleted. * @warn Deleting a guild channel cannot be undone. Use this with caution, as it is impossible to undo this action when performed on a guild channel. In contrast, when used with a private message, it is possible to undo the action by opening a private message with the recipient again. * @see https://discord.com/developers/docs/resources/channel#deleteclose-channel */ export async function deleteChannel(channelId, $req) { const res = await callDiscord(Routes.channel(channelId), { method: "DELETE", }, $req); return res.json(); } /** * Edit the channel permission overwrites for a user or role in a channel. * @info Only usable for guild channels. * @info Requires the `MANAGE_ROLES` permission. * @info Only permissions your bot has in the guild or parent channel (if applicable) can be allowed/denied (unless your bot has a `MANAGE_ROLES` overwrite in the channel). * @see https://discord.com/developers/docs/resources/channel#edit-channel-permissions */ export async function modifyChannelPermissions(channelId, overwriteId, $req) { const _res = await callDiscord(Routes.channelPermission(channelId, overwriteId), { method: "PUT", }, $req); } /** * Returns a list of [invite](https://discord.com/developers/docs/resources/invite#invite-object) objects (with [invite metadata](https://discord.com/developers/docs/resources/invite#invite-metadata-object)) for the channel. * @info Only usable for guild channels. * @info Requires the `MANAGE_CHANNELS` permission. * @see https://discord.com/developers/docs/resources/channel#get-channel-invites */ export async function listChannelInvites(channelId, $req) { const res = await callDiscord(Routes.channelInvites(channelId), { method: "GET", }, $req); return res.json(); } /** * Create a new [invite](https://discord.com/developers/docs/resources/invite#invite-object) object for the channel. * @info Only usable for guild channels. * @info Requires the `CREATE_INSTANT_INVITE` permission. * @see https://discord.com/developers/docs/resources/channel#create-channel-invite */ export async function createChannelInvite(channelId, data, $req) { const res = await callDiscord(Routes.channelInvites(channelId), { method: "POST", body: data, }, $req); return res.json(); } /** * Delete a channel permission overwrite for a user or role in a channel. * TODO rename to something like `deleteChannelPermission` * @info Only usable for guild channels. * @info Requires the `MANAGE_ROLES` permission. * @see https://discord.com/developers/docs/resources/channel#delete-channel-permission */ export async function deleteChannelPermissions(channelId, overwriteId, $req) { const _res = await callDiscord(Routes.channelPermission(channelId, overwriteId), { method: "DELETE", }, $req); } /** * Follow an Announcement Channel to send messages to a target channel. * @info Requires the `MANAGE_WEBHOOKS` permission in the target channel. * @see https://discord.com/developers/docs/resources/channel#follow-announcement-channel */ export async function followChannel(channelId, data, $req) { const res = await callDiscord(Routes.channelFollowers(channelId), { method: "POST", body: data, }, $req); return res.json(); } /** * Post a typing indicator for the specified channel, which expires after 10 seconds. * @info Generally bots should **not** use this route. * @see https://discord.com/developers/docs/resources/channel#trigger-typing-indicator */ export async function createTypingIndicator(channelId, $req) { const _res = await callDiscord(Routes.channelTyping(channelId), { method: "POST", }, $req); } /** * Adds a recipient to a Group DM using their access token. * @see https://discord.com/developers/docs/resources/channel#group-dm-add-recipient */ export async function addGDMMember(channelId, userId, $req) { const _res = await callDiscord(Routes.channelRecipient(channelId, userId), { method: "PUT", }, $req); } /** * Removes a recipient from a Group DM. * @see https://discord.com/developers/docs/resources/channel#group-dm-remove-recipient */ export async function removeGDMMember(channelId, userId, $req) { const _res = await callDiscord(Routes.channelRecipient(channelId, userId), { method: "DELETE", }, $req); } /** * Creates a new thread, include a message ID to start the thread from an existing message. * @info When called on a `GUILD_TEXT` channel, creates a `PUBLIC_THREAD`. When called on a `GUILD_ANNOUNCEMENT` channel, creates a `ANNOUNCEMENT_THREAD`. * @info Does not work on a [`GUILD_FORUM`](https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel) or a `GUILD_MEDIA` channel. * @info The id of the created thread will be the same as the id of the source message, and as such a message can only have a single thread created from it. * @see https://discord.com/developers/docs/resources/channel#start-thread-from-message */ export async function createThread(channelId, data, messageId, $req) { if (typeof data.type === "string") data.type = ChannelType[`${data.type}Thread`]; const res = await callDiscord(Routes.threads(channelId, messageId), { method: "POST", body: data, }, $req); return res.json(); } /** * Creates a new thread in a forum or a media channel, and sends a message within the created thread. * @info The type of the created thread is `PUBLIC_THREAD`. * @info The current user must have the `SEND_MESSAGES` permission (`CREATE_PUBLIC_THREADS` is ignored). * @see https://discord.com/developers/docs/resources/channel#start-thread-in-forum-or-media-channel */ export async function createForumThread(channelId, data, $req) { if (typeof data.message === "string") data.message = { content: data.message }; const res = await callDiscord(Routes.threads(channelId), { method: "POST", body: data, files: data.message.files, }, $req); return res.json(); } /** * Adds a member to a thread. * @param userId Member to add, defaults to self * @info Adding another member requires the ability to send messages in the thread. * @see https://discord.com/developers/docs/resources/channel#add-thread-member */ export async function addThreadMember(threadId, userId, $req) { const _res = await callDiscord(Routes.threadMembers(threadId, userId), { method: "PUT", }, $req); } /** * Removes a member from a thread. * @param userId Member to remove, defaults to self * @info Requires the ability to send messages in the thread. * @info Removing another member also requires the thread is not archived. * @see https://discord.com/developers/docs/resources/channel#remove-thread-member */ export async function removeThreadMember(threadId, userId, $req) { const _res = await callDiscord(Routes.threadMembers(threadId, userId), { method: "DELETE", }, $req); } /** * Returns a [thread member](https://discord.com/developers/docs/resources/channel#thread-member-object) object for the specified user if they are a member of the thread. * @info When `with_member` is set to `true`, the thread member object will include a `member` field containing a [guild member](https://discord.com/developers/docs/resources/guild#guild-member-object) object. * @see https://discord.com/developers/docs/resources/channel#get-thread-member */ export async function getThreadMember(threadId, userId, params, $req) { const res = await callDiscord(Routes.threadMembers(threadId, userId), { method: "GET", params, }, $req); return res.json(); } /** * Returns array of [thread members](https://discord.com/developers/docs/resources/channel#thread-member-object) objects that are members of the thread. * @info When `with_member` is set to `true`, the results will be paginated and each thread member object will include a `member` field containing a [guild member](https://discord.com/developers/docs/resources/guild#guild-member-object) object. * @warn Starting in API v11, this endpoint will always return paginated results. Paginated results can be enabled before API v11 by setting `with_member` to `true`. Read [the changelog](https://discord.com/developers/docs/change-log#thread-member-details-and-pagination) for details. * @warn This endpoint is restricted according to whether the `GUILD_MEMBERS` [Privileged Intent](https://discord.com/developers/docs/events/gateway#privileged-intents) is enabled for your application. * @see https://discord.com/developers/docs/resources/channel#list-thread-members */ export async function listThreadMembers(threadId, params, $req) { const res = await callDiscord(Routes.threadMembers(threadId), { method: "GET", params, }, $req); return res.json(); } /** * Returns a list of archived threads in the channel. Alternatively, returns a list of joined private threads in the channel. * @see https://discord.com/developers/docs/resources/channel#list-private-archived-threads */ export async function listArchivedThreads(channelId, archivedStatus, joinedOnly, params, $req) { const res = await callDiscord(Routes[joinedOnly ? "channelJoinedArchivedThreads" : "channelThreads"](channelId, archivedStatus), { method: "GET", params, }, $req); return res.json(); } /** * Returns a list of [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object) objects for the given guild. * @info Includes `user` fields if the bot has the `CREATE_GUILD_EXPRESSIONS` or `MANAGE_GUILD_EXPRESSIONS` permission. * @see https://discord.com/developers/docs/resources/emoji#list-guild-emojis */ export async function listEmojis(guildId, $req) { const res = await callDiscord(Routes.guildEmojis(guildId), { method: "GET", }, $req); return res.json(); } /** * Returns an [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object) object for the given guild and emoji IDs. * @info Includes the `user` field if the bot has the `MANAGE_GUILD_EXPRESSIONS` permission, or if the bot created the emoji and has the the `CREATE_GUILD_EXPRESSIONS` permission. * @see https://discord.com/developers/docs/resources/emoji#get-guild-emoji */ export async function getEmoji(guildId, emojiId, $req) { const res = await callDiscord(Routes.guildEmoji(guildId, emojiId), { method: "GET", }, $req); return res.json(); } /** * Create a new emoji for the guild. * @info Includes `user` fields if the bot has the `CREATE_GUILD_EXPRESSIONS` or `MANAGE_GUILD_EXPRESSIONS` permission. * @info We highly recommend that developers use the `.webp` extension when fetching emoji so they're rendered as WebP for maximum performance and compatibility. See the [Emoji Formats](https://discord.com/developers/docs/resources/emoji#emoji-object-emoji-formats) section above for more details. * @warn Emojis and animated emojis have a maximum file size of 256 KiB. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a [JSON status code](https://discord.com/developers/docs/topics/opcodes-and-status-codes#json). * @see https://discord.com/developers/docs/resources/emoji#create-guild-emoji */ export async function createEmoji(guildId, data, $req) { const res = await callDiscord(Routes.guildEmojis(guildId), { method: "POST", body: data, }, $req); return res.json(); } /** * Modify the given emoji. * @info For emojis created by the current user, requires either the `CREATE_GUILD_EXPRESSIONS` or `MANAGE_GUILD_EXPRESSIONS` permission. * @info For other emojis, requires the `MANAGE_GUILD_EXPRESSIONS` permission. * @see https://discord.com/developers/docs/resources/emoji#moify-guild-emoji */ export async function modifyEmoji(guildId, emojiId, data, $req) { const res = await callDiscord(Routes.guildEmoji(guildId, emojiId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Delete the given emoji. * @info For emojis created by the current user, requires either the `CREATE_GUILD_EXPRESSIONS` or `MANAGE_GUILD_EXPRESSIONS` permission. * @info For other emojis, requires the `MANAGE_GUILD_EXPRESSIONS` permission. * @see https://discord.com/developers/docs/resources/emoji#delete-guild-emoji */ export async function deleteEmoji(guildId, emojiId, $req) { const _res = await callDiscord(Routes.guildEmoji(guildId, emojiId), { method: "DELETE", }, $req); } /** * Returns an object containing a list of [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object) objects for the given application under the `items` key. * @info Includes a `user` object for the team member that uploaded the emoji from the app's settings, or for the bot user if uploaded using the API. * @see https://discord.com/developers/docs/resources/emoji#list-application-emojis */ export async function listApplicationEmojis($req) { var _a, _b; const res = await callDiscord(Routes.applicationEmojis((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "GET", }, $req); return res.json(); } /** * Returns an [emoji](https://discord.com/developers/docs/resources/emoji#emoji-object) object for the given application and emoji IDs. * @info Includes the `user` field. * @see https://discord.com/developers/docs/resources/emoji#get-application-emoji */ export async function getApplicationEmoji(emojiId, $req) { var _a, _b; const res = await callDiscord(Routes.applicationEmoji((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, emojiId), { method: "GET", }, $req); return res.json(); } /** * Create a new emoji for the application. * @info We highly recommend that developers use the `.webp` extension when fetching emoji so they're rendered as WebP for maximum performance and compatibility. See the [Emoji Formats](https://discord.com/developers/docs/resources/emoji#emoji-object-emoji-formats) section above for more details. * @warn Emojis and animated emojis have a maximum file size of 256 KiB. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a [JSON status code](https://discord.com/developers/docs/topics/opcodes-and-status-codes#json). * @see https://discord.com/developers/docs/resources/emoji#create-application-emoji */ export async function createApplicationEmoji(data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationEmojis((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "POST", body: data, }, $req); return res.json(); } /** * Modify the given emoji. * @see https://discord.com/developers/docs/resources/emoji#modify-application-emoji */ export async function modifyApplicationEmoji(emojiId, data, $req) { var _a, _b; const res = await callDiscord(Routes.applicationEmoji((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, emojiId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Delete the given emoji. * @see https://discord.com/developers/docs/resources/emoji#delete-application-emoji */ export async function deleteApplicationEmoji(emojiId, $req) { var _a, _b; const _res = await callDiscord(Routes.applicationEmoji((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, emojiId), { method: "DELETE", }, $req); } /** * Returns all entitlements for a given app, active and expired. * @see https://discord.com/developers/docs/resources/entitlement#list-entitlements */ export async function listEntitlements(params, $req) { var _a, _b; const res = await callDiscord(Routes.entitlements((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "GET", params, }, $req); return res.json(); } /** * Returns an entitlement. * @see https://discord.com/developers/docs/resources/entitlement#get-entitlement */ export async function getEntitlement(entitlementId, $req) { var _a, _b; const res = await callDiscord(Routes.entitlement((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, entitlementId), { method: "GET", }, $req); return res.json(); } /** * For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed. * @info The entitlement will have `consumed: true` when using [List Entitlements](https://discord.com/developers/docs/resources/entitlement#list-entitlements). * @see https://discord.com/developers/docs/resources/entitlement#consume-entitlement */ export async function consumeEntitlement(entitlementId, $req) { var _a, _b; const _res = await callDiscord(Routes.consumeEntitlement((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, entitlementId), { method: "POST", }, $req); } /** * Creates a test entitlement to a given SKU for a given guild or user. Discord will act as though that user or guild has entitlement to your premium offering. * @info After creating a test entitlement, you'll need to reload your Discord client. After doing so, you'll see that your server or user now has premium access. * @see https://discord.com/developers/docs/resources/entitlement#create-test-entitlement */ export async function createTestEntitlement(data, $req) { var _a, _b; const res = await callDiscord(Routes.entitlements((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID), { method: "POST", body: data, }, $req); return res.json(); } /** * Creates a test entitlement to a given SKU for a given guild or user. Discord will act as though that user or guild has entitlement to your premium offering. * @info After creating a test entitlement, you'll need to reload your Discord client. After doing so, you'll see that your server or user now has premium access. * @see https://discord.com/developers/docs/resources/entitlement#delete-test-entitlement */ export async function deleteTestEntitlement(entitlementId, $req) { var _a, _b; const _res = await callDiscord(Routes.entitlement((_b = (_a = $req === null || $req === void 0 ? void 0 : $req.env) === null || _a === void 0 ? void 0 : _a.DISCORD_APP_ID) !== null && _b !== void 0 ? _b : botEnv.DISCORD_APP_ID, entitlementId), { method: "DELETE", }, $req); } /** * Returns an object with a valid WSS URL which the app can use when [Connecting](https://discord.com/developers/docs/events/gateway#connecting) to the Gateway. Apps should cache this value and only call this endpoint to retrieve a new URL when they are unable to properly establish a connection using the cached one. * @info This endpoint does not require authentication. * @see https://discord.com/developers/docs/events/gateway#get-gateway */ export async function getGateway($req) { const res = await callDiscord(Routes.gateway(), { method: "GET", }, $req); return res.json(); } /** * Returns an object based on the information in [Get Gateway](https://discord.com/developers/docs/events/gateway#get-gateway), plus additional metadata that can help during the operation of large or [sharded](https://discord.com/developers/docs/events/gateway#sharding) bots. Unlike the [Get Gateway](https://discord.com/developers/docs/events/gateway#get-gateway), this route should not be cached for extended periods of time as the value is not guaranteed to be the same per-call, and changes as the bot joins/leaves guilds. * @warn This endpoint requires authentication using a valid bot token. * @see https://discord.com/developers/docs/events/gateway#get-gateway-bot */ export async function getGatewayBot($req) { const res = await callDiscord(Routes.gatewayBot(), { method: "GET", }, $req); return res.json(); } /** * Returns a list of [guild scheduled event](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object) objects for the given guild. * @see https://discord.com/developers/docs/resources/guild-scheduled-event#list-guild-scheduled-events */ export async function listScheduledEvents(guildId, params, $req) { const res = await callDiscord(Routes.guildScheduledEvents(guildId), { method: "GET", params, }, $req); return res.json(); } /** * Create a guild scheduled event in the guild. * @info A guild can have a maximum of 100 events with `SCHEDULED` or `ACTIVE` status at any time. * @see https://discord.com/developers/docs/resources/guild-scheduled-event#create-guild-scheduled-event */ export async function createScheduledEvent(guildId, data, $req) { const res = await callDiscord(Routes.guildScheduledEvents(guildId), { method: "POST", body: data, }, $req); return res.json(); } /** * Get a guild scheduled event. * @see https://discord.com/developers/docs/resources/guild-scheduled-event#get-guild-scheduled-event */ export async function getScheduledEvent(guildId, guildScheduledEventId, params, $req) { const res = await callDiscord(Routes.guildScheduledEvent(guildId, guildScheduledEventId), { method: "GET", params, }, $req); return res.json(); } /** * Modify a guild scheduled event. * @info To start or end an event, use this endpoint to modify the event's [status](https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-guild-scheduled-event-status) field. * @info This endpoint silently discards `entity_metadata` for non-`EXTERNAL` events. * @see https://discord.com/developers/docs/resources/guild-scheduled-event#modify-guild-scheduled-event */ export async function modifyScheduledEvent(guildId, guildScheduledEventId, data, $req) { const res = await callDiscord(Routes.guildScheduledEvent(guildId, guildScheduledEventId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Delete a guild scheduled event. * @see https://discord.com/developers/docs/resources/guild-scheduled-event#delete-guild-scheduled-event */ export async function deleteScheduledEvent(guildId, guildScheduledEventId, $req) { const _res = await callDiscord(Routes.guildScheduledEvent(guildId, guildScheduledEventId), { method: "DELETE", }, $req); } /** * Get a list of guild scheduled event users subscribed to a guild scheduled event. * @see https://discord.com/developers/docs/resources/guild-scheduled-event#get-guild-scheduled-event-users */ export async function getScheduledEventUsers(guildId, guildScheduledEventId, params, $req) { const res = await callDiscord(Routes.guildScheduledEventUsers(guildId, guildScheduledEventId), { method: "GET", params, }, $req); return res.json(); } /** * Returns a [guild template](https://discord.com/developers/docs/resources/guild-template#guild-template-object) object for the given code. * @see https://discord.com/developers/docs/resources/guild-template#get-guild-template */ export async function getTemplate(code, $req) { const res = await callDiscord(Routes.template(code), { method: "GET", }, $req); return res.json(); } /** * Returns a [guild template](https://discord.com/developers/docs/resources/guild-template#guild-template-object) object for the given code. * @see https://discord.com/developers/docs/change-log#guild-create-deprecation * @deprecated */ export async function createFromTemplate(code, data, $req) { const res = await callDiscord(Routes.template(code), { method: "POST", body: data, }, $req); return res.json(); } /** * Returns an array of [guild template](https://discord.com/developers/docs/resources/guild-template#guild-template-object) objects. * @info Requires the `MANAGE_GUILD` permission. * @see https://discord.com/developers/docs/resources/guild-template#get-guild-templates */ export async function listTemplates(guildId, $req) { const res = await callDiscord(Routes.guildTemplates(guildId), { method: "GET", }, $req); return res.json(); } /** * Creates a template for the guild. * @info Requires the `MANAGE_GUILD` permission. * @see https://discord.com/developers/docs/resources/guild-template#create-guild-template */ export async function createTemplate(guildId, data, $req) { const res = await callDiscord(Routes.guildTemplates(guildId), { method: "POST", body: data, }, $req); return res.json(); } /** * Syncs the template to the guild's current state. * @info Requires the `MANAGE_GUILD` permission. * @see https://discord.com/developers/docs/resources/guild-template#sync-guild-template */ export async function syncTemplate(guildId, code, $req) { const res = await callDiscord(Routes.guildTemplate(guildId, code), { method: "PUT", }, $req); return res.json(); } /** * Modifies the template's metadata. * @info Requires the `MANAGE_GUILD` permission. * @see https://discord.com/developers/docs/resources/guild-template#modify-guild-template */ export async function modifyTemplate(guildId, code, data, $req) { const res = await callDiscord(Routes.guildTemplate(guildId, code), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Deletes the template. * @info Requires the `MANAGE_GUILD` permission. * @see https://discord.com/developers/docs/resources/guild-template#delete-guild-template */ export async function deleteTemplate(guildId, code, $req) { const res = await callDiscord(Routes.guildTemplate(guildId, code), { method: "DELETE", }, $req); return res.json(); } /** * Create a new guild. * @see https://discord.com/developers/docs/change-log#guild-create-deprecation * @deprecated */ export async function createGuild(data, $req) { const res = await callDiscord(Routes.guilds(), { method: "POST", body: data, }, $req); return res.json(); } /** * Returns the [guild](https://discord.com/developers/docs/resources/guild#guild-object) object for the given id. * @info If `with_counts` is set to `true`, this endpoint will also return `approximate_member_count` and `approximate_presence_count` for the guild. * @see https://discord.com/developers/docs/resources/guild#get-guild */ export async function getGuild(guildId, params, $req) { const res = await callDiscord(Routes.guild(guildId), { method: "GET", params, }, $req); return res.json(); } /** * Returns the [guild preview](https://discord.com/developers/docs/resources/guild#guild-preview-object) object for the given id. * @info If the user is not in the guild, then the guild must be [discoverable](https://discord.com/developers/docs/resources/guild#guild-object-guild-features). * @see https://discord.com/developers/docs/resources/guild#get-guild-preview */ export async function getGuildPreview(guildId, $req) { const res = await callDiscord(Routes.guildPreview(guildId), { method: "GET", }, $req); return res.json(); } /** * Modify a guild's settings. * @info Requires the `MANAGE_GUILD` permission. * @warn Attempting to add or remove the `COMMUNITY` [guild feature](https://discord.com/developers/docs/resources/guild#guild-object-guild-features) requires the `ADMINISTRATOR` permission. * @see https://discord.com/developers/docs/resources/guild#modify-guild */ export async function modifyGuild(guildId, data, $req) { const res = await callDiscord(Routes.guild(guildId), { method: "PATCH", body: data, }, $req); return res.json(); } /** * Delete a guild. * @see https://discord.com/developers/docs/change-log#guild-create-deprecation * @deprecated */ export async function deleteGuild(guildId, $req) { const _res = await callDiscord(Routes.guild(guildId), { method: "DELETE", }, $req); } /** * Returns a list of guild [channel](https://discord.com/developers/docs/resources/channel#channel-object) objects. * @info Does not include threads. * @see https://discord.com/developers/docs/resources/guild#get-guild-channels */ export async function listChannels(guildId, $req) { const res = await callDiscord(Routes.guildChannels(guildId), { method: "GET", }, $req); return res.json(); } /** * Create a new [channel](https://discord.com/developers/docs/resources/channel#channel-object) object for the guild. * @info Requires the `MANAGE_CHANNELS` permission. If setting permission overwrites, only permissions your bot has in the guild can be allowed/denied. * @info Setting `MANAGE_ROLES` permission in channels is only possible for guild administrators. * @see https://discord.com/developers/docs/resources/guild#create-guild-channel */ export async function createChannel(guildId, data, $req) { const res = await callDiscord(Routes.guildChannels(guildId), { method: "POST", body: data, }, $req); return res.json(); } /** * Modify the positions of a set of [channel](https://discord.com/developers/docs/resources/channel#channel-object) objects for the guild. * @info Requires the `MANAGE_GUILD` permission. * @info Only channels to be modified are required. * @see https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions */ export async function modifyChannelPositions(guildId, data, $req) { const _res = await callDiscord(Routes.guildChannels(guildId), { method: "PATCH", body: data, }, $req); } /** * Returns all active threads in the guild, including public and private threads. * @info Threads are ordered by their `id`, in descending order. * @see https://discord.com/developers/docs/resources/guild#list-active-guild-threads */ export async function listActiveThreads(guildId, $req) { const res = await callDiscord(Routes.guildActiveThreads(guildId), { method: "GET", }, $req); return res.json(); } /** * Returns a [guild member](https://discord.com/developers/docs/resources/guild#guild-member-object) object for the specified user. * @see https://discord.com/developers/docs/resources/guild#get-guild-member */ export async function getMember(guildId, userId, $req) { const res = await callDiscord(Routes.guildMember(guildId, userId), { method: "GET", }, $req); return res.json(); } /** * Returns a list of [guild member](https://discord.com/developers/docs/resources/guild#guild-member-object) objects that are members of the guild. * @warn This endpoint is restricted according to whether the `GUILD_MEMBERS` [Privileged Intent](https://discord.com/developers/docs/events/gateway#privileged-intents) is enabled for your application. * @see https://discord.com/developers/docs/resources/guild#list-guild-members */ export async function listMembers(guildId, params, $req) { const res = await callDiscord(Routes.guildMembers(guildId), { method: "GET", params, }, $req); return res.json(); } /** * Returns a list of [guild member](https://discord.com/developers/docs/resources/guild#guild-member-object) objects whose username or nickname starts with a provided string. * @see https://discord.com/developers/docs/resources/guild#search-guild-members */ export async function searchMembers(guildId, params, $req) { const res = await callDiscord(Routes.guildMembersSearch(guildId), { method: "GET", params, }, $req); return res.json(); } /** * Adds a user to the guild, provided you have a valid oauth2 access token for the user with the `guilds.join` scope. * @info The Authorization header must be a Bot token (belonging to the same application used for authorization), and the bot must be a member of the guild with `CREATE_INSTANT_INVITE` permission. * @see https://discord.com/developers/docs/resources/guild#add-guild-member */ export async function addMember(guildId, userId, data, $req) { const res = await callDiscord(Routes.guildMember(guildId, userId), { method: "PUT", body: data, }, $req)