mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
feat(handlers/guild): add getWidget() & getWidgetImageUrl() (#420)
* feat(handlers): more get Widget functoins * forgot image jsdoc * only needed inside if * Update mod.ts * move inside if * gonna do that * Update src/api/handlers/guild.ts Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
@@ -729,6 +729,35 @@ export async function editWidget(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns the widget for the guild. */
|
||||||
|
export async function getWidget(guildID: string, options?: { force: boolean }) {
|
||||||
|
if (!options?.force) {
|
||||||
|
const guild = await cacheHandlers.get("guilds", guildID);
|
||||||
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RequestManager.get(`${endpoints.GUILD_WIDGET(guildID)}.json`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns the widget image URL for the guild. */
|
||||||
|
export async function getWidgetImageUrl(
|
||||||
|
guildID: string,
|
||||||
|
options?: {
|
||||||
|
style?: "shield" | "banner1" | "banner2" | "banner3" | "banner4";
|
||||||
|
force?: boolean;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
if (!options?.force) {
|
||||||
|
const guild = await cacheHandlers.get("guilds", guildID);
|
||||||
|
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||||
|
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${endpoints.GUILD_WIDGET(guildID)}.png?style=${options?.style ??
|
||||||
|
"shield"}`;
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the code and uses of the vanity url for this server if it is enabled. Requires the MANAGE_GUILD permission. */
|
/** Returns the code and uses of the vanity url for this server if it is enabled. Requires the MANAGE_GUILD permission. */
|
||||||
export async function getVanityURL(guildID: string) {
|
export async function getVanityURL(guildID: string) {
|
||||||
const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildID));
|
const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildID));
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ import {
|
|||||||
getVanityURL,
|
getVanityURL,
|
||||||
getVoiceRegions,
|
getVoiceRegions,
|
||||||
getWebhooks,
|
getWebhooks,
|
||||||
|
getWidget,
|
||||||
|
getWidgetImageUrl,
|
||||||
getWidgetSettings,
|
getWidgetSettings,
|
||||||
guildBannerURL,
|
guildBannerURL,
|
||||||
guildIconURL,
|
guildIconURL,
|
||||||
@@ -193,6 +195,8 @@ export let handlers = {
|
|||||||
getVanityURL,
|
getVanityURL,
|
||||||
getVoiceRegions,
|
getVoiceRegions,
|
||||||
getWebhooks,
|
getWebhooks,
|
||||||
|
getWidget,
|
||||||
|
getWidgetImageUrl,
|
||||||
guildBannerURL,
|
guildBannerURL,
|
||||||
guildIconURL,
|
guildIconURL,
|
||||||
guildSplashURL,
|
guildSplashURL,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export enum Errors {
|
|||||||
UPDATES_CHANNEL_CANNOT_BE_DELETED = "UPDATES_CHANNEL_CANNOT_BE_DELETED",
|
UPDATES_CHANNEL_CANNOT_BE_DELETED = "UPDATES_CHANNEL_CANNOT_BE_DELETED",
|
||||||
// Guild Errors
|
// Guild Errors
|
||||||
GUILD_NOT_DISCOVERABLE = "GUILD_NOT_DISCOVERABLE",
|
GUILD_NOT_DISCOVERABLE = "GUILD_NOT_DISCOVERABLE",
|
||||||
|
GUILD_WIDGET_NOT_ENABLED = "GUILD_WIDGET_NOT_ENABLED",
|
||||||
GUILD_NOT_FOUND = "GUILD_NOT_FOUND",
|
GUILD_NOT_FOUND = "GUILD_NOT_FOUND",
|
||||||
MEMBER_NOT_FOUND = "MEMBER_NOT_FOUND",
|
MEMBER_NOT_FOUND = "MEMBER_NOT_FOUND",
|
||||||
PRUNE_MAX_DAYS = "PRUNE_MAX_DAYS",
|
PRUNE_MAX_DAYS = "PRUNE_MAX_DAYS",
|
||||||
|
|||||||
Reference in New Issue
Block a user