22
33const { Collection } = require ( '@discordjs/collection' ) ;
44const { makeURLSearchParams } = require ( '@discordjs/rest' ) ;
5+ const { DiscordSnowflake } = require ( '@sapphire/snowflake' ) ;
56const { ChannelType, GuildPremiumTier, Routes, GuildFeature } = require ( 'discord-api-types/v10' ) ;
67const AnonymousGuild = require ( './AnonymousGuild' ) ;
78const GuildAuditLogs = require ( './GuildAuditLogs' ) ;
@@ -28,7 +29,7 @@ const VoiceStateManager = require('../managers/VoiceStateManager');
2829const DataResolver = require ( '../util/DataResolver' ) ;
2930const Status = require ( '../util/Status' ) ;
3031const SystemChannelFlagsBitField = require ( '../util/SystemChannelFlagsBitField' ) ;
31- const { discordSort, getSortableGroupTypes } = require ( '../util/Util' ) ;
32+ const { discordSort, getSortableGroupTypes, resolvePartialEmoji } = require ( '../util/Util' ) ;
3233
3334/**
3435 * Represents a guild (or a server) on Discord.
@@ -881,6 +882,85 @@ class Guild extends AnonymousGuild {
881882 return this . client . actions . GuildUpdate . handle ( data ) . updated ;
882883 }
883884
885+ /**
886+ * Options used to edit the guild onboarding.
887+ * @typedef {Object } GuildOnboardingEditOptions
888+ * @property {GuildOnboardingPromptData[]|Collection<Snowflake, GuildOnboardingPrompt> } [prompts]
889+ * The prompts shown during onboarding and in customize community
890+ * @property {ChannelResolvable[]|Collection<Snowflake, GuildChannel> } [defaultChannels]
891+ * The channels that new members get opted into automatically
892+ * @property {boolean } [enabled] Whether the onboarding is enabled
893+ * @property {GuildOnboardingMode } [mode] The mode to edit the guild onboarding with
894+ * @property {string } [reason] The reason for editing the guild onboarding
895+ */
896+
897+ /**
898+ * Data for editing a guild onboarding prompt.
899+ * @typedef {Object } GuildOnboardingPromptData
900+ * @property {Snowflake } [id] The id of the prompt
901+ * @property {string } title The title for the prompt
902+ * @property {boolean } [singleSelect] Whether users are limited to selecting one option for the prompt
903+ * @property {boolean } [required] Whether the prompt is required before a user completes the onboarding flow
904+ * @property {boolean } [inOnboarding] Whether the prompt is present in the onboarding flow
905+ * @property {GuildOnboardingPromptType } [type] The type of the prompt
906+ * @property {GuildOnboardingPromptOptionData[]|Collection<Snowflake, GuildOnboardingPrompt> } options
907+ * The options available within the prompt
908+ */
909+
910+ /**
911+ * Data for editing a guild onboarding prompt option.
912+ * @typedef {Object } GuildOnboardingPromptOptionData
913+ * @property {?Snowflake } [id] The id of the option
914+ * @property {ChannelResolvable[]|Collection<Snowflake, GuildChannel> } [channels]
915+ * The channels a member is added to when the option is selected
916+ * @property {RoleResolvable[]|Collection<Snowflake, Role> } [roles]
917+ * The roles assigned to a member when the option is selected
918+ * @property {string } title The title of the option
919+ * @property {?string } [description] The description of the option
920+ * @property {?(EmojiIdentifierResolvable|Emoji) } [emoji] The emoji of the option
921+ */
922+
923+ /**
924+ * Edits the guild onboarding data for this guild.
925+ * @param {GuildOnboardingEditOptions } options The options to provide
926+ * @returns {Promise<GuildOnboarding> }
927+ */
928+ async editOnboarding ( options ) {
929+ const newData = await this . client . rest . put ( Routes . guildOnboarding ( this . id ) , {
930+ body : {
931+ prompts : options . prompts ?. map ( prompt => ( {
932+ // Currently, the prompt ids are required even for new ones (which won't be used)
933+ id : prompt . id ?? DiscordSnowflake . generate ( ) . toString ( ) ,
934+ title : prompt . title ,
935+ single_select : prompt . singleSelect ,
936+ required : prompt . required ,
937+ in_onboarding : prompt . inOnboarding ,
938+ type : prompt . type ,
939+ options : prompt . options . map ( option => {
940+ const emoji = resolvePartialEmoji ( option . emoji ) ;
941+
942+ return {
943+ id : option . id ,
944+ channel_ids : option . channels ?. map ( channel => this . channels . resolveId ( channel ) ) ,
945+ role_ids : option . roles ?. map ( role => this . roles . resolveId ( role ) ) ,
946+ title : option . title ,
947+ description : option . description ,
948+ emoji_animated : emoji ?. animated ,
949+ emoji_id : emoji ?. id ,
950+ emoji_name : emoji ?. name ,
951+ } ;
952+ } ) ,
953+ } ) ) ,
954+ default_channel_ids : options . defaultChannels ?. map ( channel => this . channels . resolveId ( channel ) ) ,
955+ enabled : options . enabled ,
956+ mode : options . mode ,
957+ } ,
958+ reason : options . reason ,
959+ } ) ;
960+
961+ return new GuildOnboarding ( this . client , newData ) ;
962+ }
963+
884964 /**
885965 * Welcome channel data
886966 * @typedef {Object } WelcomeChannelData
0 commit comments