Files
discordeno/helpers/discovery/editDiscovery.ts
ITOH 03996c5f58 refactor: revert "feat: base plugin lib idea (#2308)" (#2336)
* Revert "feat: base plugin lib idea (#2308)"

This reverts commit ffe7cdbc6f.

* fmt
2022-07-02 14:24:43 +01:00

41 lines
1.6 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { DiscordDiscoveryMetadata } from "../../types/discord.ts";
/** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */
export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) {
const result = await bot.rest.runMethod<DiscordDiscoveryMetadata>(
bot.rest,
"PATCH",
bot.constants.routes.DISCOVERY_METADATA(guildId),
{
primary_category_id: data.primaryCategoryId,
keywords: data.keywords,
emoji_discoverability_enabled: data.emojiDiscoverabilityEnabled,
},
);
return {
guildId,
primaryCategoryId: result.primary_category_id,
keywords: result.keywords ?? undefined,
emojiDiscoverabilityEnabled: result.emoji_discoverability_enabled,
partnerActionedTimestamp: result.partner_actioned_timestamp
? Date.parse(result.partner_actioned_timestamp)
: undefined,
partnerApplicationTimestamp: result.partner_application_timestamp
? Date.parse(result.partner_application_timestamp)
: undefined,
categoryIds: result.category_ids,
};
}
// TODO: add docs link
export interface ModifyGuildDiscoveryMetadata {
/** The id of the primary discovery category. Default: 0 */
primaryCategoryId?: number | null;
/** Up to 10 discovery search keywords. Default: null */
keywords?: string[] | null;
/** Whether guild info is shown when custom emojis are clicked. Default: true */
emojiDiscoverabilityEnabled?: boolean | null;
}