mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
feat(handlers): add getEmoji() & getEmojis() (#406)
* add(handlers): getEmojis * add(handlers): getEmoji * fix cache * addToCache argument * addtocache default to true * Update guild.ts * remove this * Update src/api/handlers/guild.ts Co-authored-by: Ayyan <ayyantee@gmail.com> * Update src/api/handlers/guild.ts Co-authored-by: Ayyan <ayyantee@gmail.com> Co-authored-by: Ayyan <ayyantee@gmail.com>
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
EditEmojisOptions,
|
EditEmojisOptions,
|
||||||
EditGuildTemplate,
|
EditGuildTemplate,
|
||||||
EditIntegrationOptions,
|
EditIntegrationOptions,
|
||||||
|
Emoji,
|
||||||
Errors,
|
Errors,
|
||||||
FetchMembersOptions,
|
FetchMembersOptions,
|
||||||
GetAuditLogsOptions,
|
GetAuditLogsOptions,
|
||||||
@@ -349,6 +350,54 @@ export function emojiURL(id: string, animated = false) {
|
|||||||
return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`;
|
return `https://cdn.discordapp.com/emojis/${id}.${animated ? "gif" : "png"}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of emojis for the given guild.
|
||||||
|
*
|
||||||
|
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
||||||
|
*/
|
||||||
|
export async function getEmojis(guildID: string, addToCache = true) {
|
||||||
|
const result = await RequestManager.get(
|
||||||
|
endpoints.GUILD_EMOJIS(guildID),
|
||||||
|
) as Emoji[];
|
||||||
|
|
||||||
|
if (addToCache) {
|
||||||
|
const guild = await cacheHandlers.get("guilds", guildID);
|
||||||
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
guild.emojis = result;
|
||||||
|
cacheHandlers.set("guilds", guildID, guild);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an emoji for the given guild and emoji ID.
|
||||||
|
*
|
||||||
|
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()?.emojis
|
||||||
|
*/
|
||||||
|
export async function getEmoji(
|
||||||
|
guildID: string,
|
||||||
|
emojiID: string,
|
||||||
|
addToCache = true,
|
||||||
|
) {
|
||||||
|
const result = await RequestManager.get(
|
||||||
|
endpoints.GUILD_EMOJI(guildID, emojiID),
|
||||||
|
) as Emoji;
|
||||||
|
|
||||||
|
if (addToCache) {
|
||||||
|
const guild = await cacheHandlers.get("guilds", guildID);
|
||||||
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
guild.emojis.push(result);
|
||||||
|
cacheHandlers.set(
|
||||||
|
"guilds",
|
||||||
|
guildID,
|
||||||
|
guild,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
|
/** Create a new role for the guild. Requires the MANAGE_ROLES permission. */
|
||||||
export async function createGuildRole(
|
export async function createGuildRole(
|
||||||
guildID: string,
|
guildID: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user