diff --git a/packages/bot/src/helpers.ts b/packages/bot/src/helpers.ts index 3d0c9be1e..7c3104ce1 100644 --- a/packages/bot/src/helpers.ts +++ b/packages/bot/src/helpers.ts @@ -26,6 +26,7 @@ import type { CamelizedDiscordVanityUrl, CamelizedDiscordVoiceRegion, CreateApplicationCommand, + CreateApplicationEmoji, CreateAutoModerationRuleOptions, CreateChannelInvite, CreateEntitlement, @@ -77,6 +78,7 @@ import type { ListArchivedThreads, ListGuildMembers, MfaLevels, + ModifyApplicationEmoji, ModifyChannel, ModifyGuild, ModifyGuildChannelPositions, @@ -133,6 +135,9 @@ export function createBotHelpers(bot: Bot): BotHelpers { createEmoji: async (guildId, options, reason) => { return bot.transformers.emoji(bot, snakelize(await bot.rest.createEmoji(guildId, options, reason))) }, + createApplicationEmoji: async (options) => { + return bot.transformers.emoji(bot, snakelize(await bot.rest.createApplicationEmoji(options))) + }, createForumThread: async (channelId, options, reason) => { return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.createForumThread(channelId, options, reason)) }) }, @@ -187,6 +192,9 @@ export function createBotHelpers(bot: Bot): BotHelpers { editEmoji: async (guildId, id, options, reason) => { return bot.transformers.emoji(bot, snakelize(await bot.rest.editEmoji(guildId, id, options, reason))) }, + editApplicationEmoji: async (id, options) => { + return bot.transformers.emoji(bot, snakelize(await bot.rest.editApplicationEmoji(id, options))) + }, editFollowupMessage: async (token, messageId, options) => { return bot.transformers.message(bot, snakelize(await bot.rest.editFollowupMessage(token, messageId, options))) }, @@ -323,9 +331,19 @@ export function createBotHelpers(bot: Bot): BotHelpers { getEmoji: async (guildId, emojiId) => { return bot.transformers.emoji(bot, snakelize(await bot.rest.getEmoji(guildId, emojiId))) }, + getApplicationEmoji: async (emojiId) => { + return bot.transformers.emoji(bot, snakelize(await bot.rest.getApplicationEmoji(emojiId))) + }, getEmojis: async (guildId) => { return (await bot.rest.getEmojis(guildId)).map((res) => bot.transformers.emoji(bot, snakelize(res))) }, + getApplicationEmojis: async () => { + const res = await bot.rest.getApplicationEmojis() + + return { + items: res.items.map((item) => bot.transformers.emoji(bot, snakelize(item))), + } + }, getFollowupMessage: async (token, messageId) => { return bot.transformers.message(bot, snakelize(await bot.rest.getFollowupMessage(token, messageId))) }, @@ -578,6 +596,9 @@ export function createBotHelpers(bot: Bot): BotHelpers { deleteEmoji: async (guildId, id, reason) => { return await bot.rest.deleteEmoji(guildId, id, reason) }, + deleteApplicationEmoji: async (id) => { + return await bot.rest.deleteApplicationEmoji(id) + }, deleteFollowupMessage: async (token, messageId) => { return await bot.rest.deleteFollowupMessage(token, messageId) }, @@ -723,6 +744,7 @@ export interface BotHelpers { createAutomodRule: (guildId: BigString, options: CreateAutoModerationRuleOptions, reason?: string) => Promise createChannel: (guildId: BigString, options: CreateGuildChannel, reason?: string) => Promise createEmoji: (guildId: BigString, options: CreateGuildEmoji, reason?: string) => Promise + createApplicationEmoji: (options: CreateApplicationEmoji) => Promise createForumThread: (channelId: BigString, options: CreateForumPostWithMessage, reason?: string) => Promise createGlobalApplicationCommand: (command: CreateApplicationCommand, options?: CreateGlobalApplicationCommandOptions) => Promise createGuild: (options: CreateGuild) => Promise @@ -754,6 +776,7 @@ export interface BotHelpers { editBotProfile: (options: { username?: string; botAvatarURL?: string | null }) => Promise editChannel: (channelId: BigString, options: ModifyChannel, reason?: string) => Promise editEmoji: (guildId: BigString, id: BigString, options: ModifyGuildEmoji, reason?: string) => Promise + editApplicationEmoji: (id: BigString, options: ModifyApplicationEmoji) => Promise editFollowupMessage: (token: string, messageId: BigString, options: InteractionCallbackData) => Promise editGlobalApplicationCommand: (commandId: BigString, options: CreateApplicationCommand) => Promise editGuild: (guildId: BigString, options: ModifyGuild, reason?: string) => Promise @@ -812,7 +835,9 @@ export interface BotHelpers { getDmChannel: (userId: BigString) => Promise getGroupDmChannel: (options: GetGroupDmOptions) => Promise getEmoji: (guildId: BigString, emojiId: BigString) => Promise + getApplicationEmoji: (emojiId: BigString) => Promise getEmojis: (guildId: BigString) => Promise + getApplicationEmojis: () => Promise<{ items: Emoji[] }> getFollowupMessage: (token: string, messageId: BigString) => Promise getGatewayBot: () => Promise getGlobalApplicationCommand: (commandId: BigString) => Promise @@ -899,6 +924,7 @@ export interface BotHelpers { deleteChannel: (channelId: BigString, reason?: string) => Promise deleteChannelPermissionOverride: (channelId: BigString, overwriteId: BigString, reason?: string) => Promise deleteEmoji: (guildId: BigString, id: BigString, reason?: string) => Promise + deleteApplicationEmoji: (id: BigString) => Promise deleteFollowupMessage: (token: string, messageId: BigString) => Promise deleteGlobalApplicationCommand: (commandId: BigString) => Promise deleteGuild: (guildId: BigString) => Promise diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 2e4eaae3b..52b730621 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -633,6 +633,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.post(rest.routes.guilds.emojis(guildId), { body, reason }) }, + async createApplicationEmoji(body) { + return await rest.post(rest.routes.applicationEmojis(rest.applicationId), { body }) + }, + async createGlobalApplicationCommand(body, options) { const restOptions: MakeRequestOptions = { body } @@ -733,6 +737,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage await rest.delete(rest.routes.guilds.emoji(guildId, id), { reason }) }, + async deleteApplicationEmoji(id) { + await rest.delete(rest.routes.applicationEmoji(rest.applicationId, id)) + }, + async deleteFollowupMessage(token, messageId) { await rest.delete(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), { unauthorized: true }) }, @@ -875,6 +883,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.patch(rest.routes.guilds.emoji(guildId, id), { body, reason }) }, + async editApplicationEmoji(id, body) { + return await rest.patch(rest.routes.applicationEmoji(rest.applicationId, id), { body }) + }, + async editFollowupMessage(token, messageId, body) { return await rest.patch(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), { body, @@ -1149,10 +1161,18 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage return await rest.get(rest.routes.guilds.emoji(guildId, emojiId)) }, + async getApplicationEmoji(emojiId) { + return await rest.get(rest.routes.applicationEmoji(rest.applicationId, emojiId)) + }, + async getEmojis(guildId) { return await rest.get(rest.routes.guilds.emojis(guildId)) }, + async getApplicationEmojis() { + return await rest.get<{ items: DiscordEmoji[] }>(rest.routes.applicationEmojis(rest.applicationId)) + }, + async getFollowupMessage(token, messageId) { return await rest.get(rest.routes.interactions.responses.message(rest.applicationId, token, messageId), { unauthorized: true }) }, diff --git a/packages/rest/src/routes.ts b/packages/rest/src/routes.ts index 8c2b29ab8..b7b66ff9d 100644 --- a/packages/rest/src/routes.ts +++ b/packages/rest/src/routes.ts @@ -595,6 +595,14 @@ export function createRoutes(): RestRoutes { }, }, + applicationEmoji(applicationId, emojiId) { + return `/applications/${applicationId}/emojis/${emojiId}` + }, + + applicationEmojis(applicationId) { + return `/applications/${applicationId}/emojis` + }, + // User endpoints user(userId) { return `/users/${userId}` diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index 6bdd32f4c..043df1203 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -56,6 +56,7 @@ import type { // eslint-disable-next-line @typescript-eslint/no-unused-vars ChannelTypes, CreateApplicationCommand, + CreateApplicationEmoji, CreateAutoModerationRuleOptions, CreateChannelInvite, CreateEntitlement, @@ -115,6 +116,7 @@ import type { ListArchivedThreads, ListGuildMembers, MfaLevels, + ModifyApplicationEmoji, ModifyChannel, ModifyGuild, ModifyGuildChannelPositions, @@ -415,6 +417,15 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/emoji#create-guild-emoji} */ createEmoji: (guildId: BigString, options: CreateGuildEmoji, reason?: string) => Promise + /** + * Creates an emoji for the application. + * + * @param options - The parameters for the creation of the emoji. + * @returns An instance of the created {@link CamelizedDiscordEmoji}. + * + * @see {@link https://discord.com/developers/docs/resources/emoji#create-application-emoji} + */ + createApplicationEmoji: (options: CreateApplicationEmoji) => Promise /** * Creates a new thread in a forum channel or media channel, and sends a message within the created thread. * @@ -693,6 +704,14 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/emoji#delete-guild-emoji} */ deleteEmoji: (guildId: BigString, id: BigString, reason?: string) => Promise + /** + * Deletes an emoji from the application. + * + * @param id - The ID of the emoji to delete. + * + * @see {@link https://discord.com/developers/docs/resources/emoji#delete-application-emoji} + */ + deleteApplicationEmoji: (id: BigString) => Promise /** * Deletes a follow-up message to an interaction. * @@ -1121,6 +1140,16 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/emoji#modify-guild-emoji} */ editEmoji: (guildId: BigString, id: BigString, options: ModifyGuildEmoji, reason?: string) => Promise + /** + * Edits an application emoji. + * + * @param id - The ID of the emoji to edit. + * @param options - The parameters for the edit of the emoji. + * @returns An instance of the updated {@link CamelizedDiscordEmoji}. + * + * @see {@link https://discord.com/developers/docs/resources/emoji#modify-application-emoji} + */ + editApplicationEmoji: (id: BigString, options: ModifyApplicationEmoji) => Promise /** * Edits a follow-up message to an interaction. * @@ -1765,6 +1794,18 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/emoji#get-guild-emoji} */ getEmoji: (guildId: BigString, emojiId: BigString) => Promise + /** + * Gets an application emoji by its ID. + * + * @param emojiId - The ID of the emoji to get. + * @returns An instance of {@link CamelizedDiscordEmoji}. + * + * @remarks + * Always includes the `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 {@link https://discord.com/developers/docs/resources/emoji#get-application-emoji} + */ + getApplicationEmoji: (emojiId: BigString) => Promise /** * Gets the list of emojis for a guild. * @@ -1777,6 +1818,17 @@ export interface RestManager { * @see {@link https://discord.com/developers/docs/resources/emoji#list-guild-emojis} */ getEmojis: (guildId: BigString) => Promise + /** + * Gets the list of emojis for an application. + * + * @returns An object with the array of {@link CamelizedDiscordEmoji} objects. + * + * @remarks + * Always includes the `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 {@link https://discord.com/developers/docs/resources/emoji#list-application-emojis} + */ + getApplicationEmojis: () => Promise<{ items: CamelizedDiscordEmoji[] }> /** * Gets a follow-up message to an interaction by the ID of the message. * diff --git a/packages/rest/src/typings/routes.ts b/packages/rest/src/typings/routes.ts index c392cd51c..543053c6a 100644 --- a/packages/rest/src/typings/routes.ts +++ b/packages/rest/src/typings/routes.ts @@ -273,9 +273,13 @@ export interface RestRoutes { /** Route to list the SKUs */ skus: (applicationId: BigString) => string } + /** Route to list / create an application emoji */ + applicationEmojis: (applicationId: BigString) => string + /** Route to get / edit / delete an application emoji */ + applicationEmoji: (applicationId: BigString, emojiId: BigString) => string /** Get information about the current OAuth2 user / bot user. If used with a OAuth2 token requires the `identify` OAuth2 scope */ currentUser: () => string - /** Route to get and edit information about the current application. */ + /** Route to get and edit information about the current application. */ application: () => string /** Route for handling a sticker. */ sticker: (stickerId: BigString) => string diff --git a/packages/types/src/discordeno.ts b/packages/types/src/discordeno.ts index 9f46b08b5..c0d9abcc1 100644 --- a/packages/types/src/discordeno.ts +++ b/packages/types/src/discordeno.ts @@ -544,6 +544,14 @@ export interface CreateGuildEmoji { roles?: BigString[] } +/** https://discord.com/developers/docs/resources/emoji#create-application-emoji */ +export interface CreateApplicationEmoji { + /** Name of the emoji */ + name: string + /** The 128x128 emoji image. Emojis and animated emojis have a maximum file size of 256kb. 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. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */ + image: string +} + /** https://discord.com/developers/docs/resources/emoji#modify-guild-emoji */ export interface ModifyGuildEmoji { /** Name of the emoji */ @@ -552,6 +560,12 @@ export interface ModifyGuildEmoji { roles?: BigString[] | null } +/** https://discord.com/developers/docs/resources/emoji#modify-application-emoji */ +export interface ModifyApplicationEmoji { + /** Name of the emoji */ + name?: string +} + /** https://discord.com/developers/docs/topics/gateway#request-guild-members */ export interface RequestGuildMembers { /** id of the guild to get members for */