Skip to content

Commit dc73c93

Browse files
feat: guild onboarding (#9120)
* feat: guild onboarding * feat: types and /core method * fix: route * fix: make emoji name non-nullable --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent a48d0ef commit dc73c93

File tree

9 files changed

+393
-92
lines changed

9 files changed

+393
-92
lines changed

packages/core/src/api/guild.ts

Lines changed: 104 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,99 @@
11
/* eslint-disable jsdoc/check-param-names */
22

33
import { makeURLSearchParams, type REST, type RawFile, type RequestData } from '@discordjs/rest';
4-
import { Routes } from 'discord-api-types/v10';
5-
import type {
6-
RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
7-
RESTPatchAPIGuildVoiceStateCurrentMemberResult,
8-
GuildMFALevel,
9-
GuildWidgetStyle,
10-
RESTGetAPIAuditLogQuery,
11-
RESTGetAPIAuditLogResult,
12-
RESTGetAPIAutoModerationRuleResult,
13-
RESTGetAPIAutoModerationRulesResult,
14-
RESTGetAPIGuildBanResult,
15-
RESTGetAPIGuildBansQuery,
16-
RESTGetAPIGuildBansResult,
17-
RESTGetAPIGuildChannelsResult,
18-
RESTGetAPIGuildEmojiResult,
19-
RESTGetAPIGuildEmojisResult,
20-
RESTGetAPIGuildIntegrationsResult,
21-
RESTGetAPIGuildInvitesResult,
22-
RESTGetAPIGuildMemberResult,
23-
RESTGetAPIGuildMembersResult,
24-
RESTGetAPIGuildMembersQuery,
25-
RESTGetAPIGuildMembersSearchResult,
26-
RESTGetAPIGuildPreviewResult,
27-
RESTGetAPIGuildPruneCountResult,
28-
RESTGetAPIGuildResult,
29-
RESTGetAPIGuildRolesResult,
30-
RESTGetAPIGuildScheduledEventQuery,
31-
RESTGetAPIGuildScheduledEventResult,
32-
RESTGetAPIGuildScheduledEventsQuery,
33-
RESTGetAPIGuildScheduledEventsResult,
34-
RESTGetAPIGuildScheduledEventUsersQuery,
35-
RESTGetAPIGuildScheduledEventUsersResult,
36-
RESTGetAPIGuildStickerResult,
37-
RESTGetAPIGuildStickersResult,
38-
RESTGetAPIGuildTemplatesResult,
39-
RESTGetAPIGuildThreadsResult,
40-
RESTGetAPIGuildVanityUrlResult,
41-
RESTGetAPIGuildVoiceRegionsResult,
42-
RESTGetAPIGuildPruneCountQuery,
43-
RESTPostAPIGuildStickerFormDataBody,
44-
RESTPostAPIGuildStickerResult,
45-
RESTGetAPIGuildMembersSearchQuery,
46-
RESTGetAPIGuildWebhooksResult,
47-
RESTGetAPIGuildWelcomeScreenResult,
48-
RESTGetAPIGuildWidgetImageResult,
49-
RESTGetAPIGuildWidgetJSONResult,
50-
RESTGetAPIGuildWidgetSettingsResult,
51-
RESTGetAPITemplateResult,
52-
RESTPatchAPIAutoModerationRuleJSONBody,
53-
RESTPatchAPIAutoModerationRuleResult,
54-
RESTPatchAPIGuildChannelPositionsJSONBody,
55-
RESTPatchAPIGuildEmojiJSONBody,
56-
RESTPatchAPIGuildEmojiResult,
57-
RESTPatchAPIGuildJSONBody,
58-
RESTPatchAPIGuildMemberJSONBody,
59-
RESTPatchAPIGuildMemberResult,
60-
RESTPatchAPIGuildResult,
61-
RESTPatchAPIGuildRoleJSONBody,
62-
RESTPatchAPIGuildRolePositionsJSONBody,
63-
RESTPatchAPIGuildRolePositionsResult,
64-
RESTPatchAPIGuildRoleResult,
65-
RESTPatchAPIGuildScheduledEventJSONBody,
66-
RESTPatchAPIGuildScheduledEventResult,
67-
RESTPatchAPIGuildStickerJSONBody,
68-
RESTPatchAPIGuildStickerResult,
69-
RESTPatchAPIGuildTemplateJSONBody,
70-
RESTPatchAPIGuildTemplateResult,
71-
RESTPatchAPIGuildVoiceStateUserJSONBody,
72-
RESTPatchAPIGuildWelcomeScreenJSONBody,
73-
RESTPatchAPIGuildWelcomeScreenResult,
74-
RESTPatchAPIGuildWidgetSettingsJSONBody,
75-
RESTPatchAPIGuildWidgetSettingsResult,
76-
RESTPostAPIAutoModerationRuleJSONBody,
77-
RESTPostAPIAutoModerationRuleResult,
78-
RESTPostAPIGuildChannelJSONBody,
79-
RESTPostAPIGuildChannelResult,
80-
RESTPostAPIGuildEmojiJSONBody,
81-
RESTPostAPIGuildEmojiResult,
82-
RESTPostAPIGuildPruneJSONBody,
83-
RESTPostAPIGuildPruneResult,
84-
RESTPostAPIGuildRoleJSONBody,
85-
RESTPostAPIGuildRoleResult,
86-
RESTPostAPIGuildScheduledEventJSONBody,
87-
RESTPostAPIGuildScheduledEventResult,
88-
RESTPostAPIGuildsJSONBody,
89-
RESTPostAPIGuildsMFAResult,
90-
RESTPostAPIGuildsResult,
91-
RESTPostAPIGuildTemplatesJSONBody,
92-
RESTPostAPIGuildTemplatesResult,
93-
RESTPutAPIGuildBanJSONBody,
94-
RESTPutAPIGuildTemplateSyncResult,
95-
Snowflake,
4+
import {
5+
Routes,
6+
type GuildMFALevel,
7+
type GuildWidgetStyle,
8+
type RESTGetAPIAuditLogQuery,
9+
type RESTGetAPIAuditLogResult,
10+
type RESTGetAPIAutoModerationRuleResult,
11+
type RESTGetAPIAutoModerationRulesResult,
12+
type RESTGetAPIGuildBanResult,
13+
type RESTGetAPIGuildBansQuery,
14+
type RESTGetAPIGuildBansResult,
15+
type RESTGetAPIGuildChannelsResult,
16+
type RESTGetAPIGuildEmojiResult,
17+
type RESTGetAPIGuildEmojisResult,
18+
type RESTGetAPIGuildIntegrationsResult,
19+
type RESTGetAPIGuildInvitesResult,
20+
type RESTGetAPIGuildMemberResult,
21+
type RESTGetAPIGuildMembersQuery,
22+
type RESTGetAPIGuildMembersResult,
23+
type RESTGetAPIGuildMembersSearchQuery,
24+
type RESTGetAPIGuildMembersSearchResult,
25+
type RESTGetAPIGuildOnboardingResult,
26+
type RESTGetAPIGuildPreviewResult,
27+
type RESTGetAPIGuildPruneCountQuery,
28+
type RESTGetAPIGuildPruneCountResult,
29+
type RESTGetAPIGuildResult,
30+
type RESTGetAPIGuildRolesResult,
31+
type RESTGetAPIGuildScheduledEventQuery,
32+
type RESTGetAPIGuildScheduledEventResult,
33+
type RESTGetAPIGuildScheduledEventUsersQuery,
34+
type RESTGetAPIGuildScheduledEventUsersResult,
35+
type RESTGetAPIGuildScheduledEventsQuery,
36+
type RESTGetAPIGuildScheduledEventsResult,
37+
type RESTGetAPIGuildStickerResult,
38+
type RESTGetAPIGuildStickersResult,
39+
type RESTGetAPIGuildTemplatesResult,
40+
type RESTGetAPIGuildThreadsResult,
41+
type RESTGetAPIGuildVanityUrlResult,
42+
type RESTGetAPIGuildVoiceRegionsResult,
43+
type RESTGetAPIGuildWebhooksResult,
44+
type RESTGetAPIGuildWelcomeScreenResult,
45+
type RESTGetAPIGuildWidgetImageResult,
46+
type RESTGetAPIGuildWidgetJSONResult,
47+
type RESTGetAPIGuildWidgetSettingsResult,
48+
type RESTGetAPITemplateResult,
49+
type RESTPatchAPIAutoModerationRuleJSONBody,
50+
type RESTPatchAPIAutoModerationRuleResult,
51+
type RESTPatchAPIGuildChannelPositionsJSONBody,
52+
type RESTPatchAPIGuildEmojiJSONBody,
53+
type RESTPatchAPIGuildEmojiResult,
54+
type RESTPatchAPIGuildJSONBody,
55+
type RESTPatchAPIGuildMemberJSONBody,
56+
type RESTPatchAPIGuildMemberResult,
57+
type RESTPatchAPIGuildResult,
58+
type RESTPatchAPIGuildRoleJSONBody,
59+
type RESTPatchAPIGuildRolePositionsJSONBody,
60+
type RESTPatchAPIGuildRolePositionsResult,
61+
type RESTPatchAPIGuildRoleResult,
62+
type RESTPatchAPIGuildScheduledEventJSONBody,
63+
type RESTPatchAPIGuildScheduledEventResult,
64+
type RESTPatchAPIGuildStickerJSONBody,
65+
type RESTPatchAPIGuildStickerResult,
66+
type RESTPatchAPIGuildTemplateJSONBody,
67+
type RESTPatchAPIGuildTemplateResult,
68+
type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody,
69+
type RESTPatchAPIGuildVoiceStateCurrentMemberResult,
70+
type RESTPatchAPIGuildVoiceStateUserJSONBody,
71+
type RESTPatchAPIGuildWelcomeScreenJSONBody,
72+
type RESTPatchAPIGuildWelcomeScreenResult,
73+
type RESTPatchAPIGuildWidgetSettingsJSONBody,
74+
type RESTPatchAPIGuildWidgetSettingsResult,
75+
type RESTPostAPIAutoModerationRuleJSONBody,
76+
type RESTPostAPIAutoModerationRuleResult,
77+
type RESTPostAPIGuildChannelJSONBody,
78+
type RESTPostAPIGuildChannelResult,
79+
type RESTPostAPIGuildEmojiJSONBody,
80+
type RESTPostAPIGuildEmojiResult,
81+
type RESTPostAPIGuildPruneJSONBody,
82+
type RESTPostAPIGuildPruneResult,
83+
type RESTPostAPIGuildRoleJSONBody,
84+
type RESTPostAPIGuildRoleResult,
85+
type RESTPostAPIGuildScheduledEventJSONBody,
86+
type RESTPostAPIGuildScheduledEventResult,
87+
type RESTPostAPIGuildStickerFormDataBody,
88+
type RESTPostAPIGuildStickerResult,
89+
type RESTPostAPIGuildTemplatesJSONBody,
90+
type RESTPostAPIGuildTemplatesResult,
91+
type RESTPostAPIGuildsJSONBody,
92+
type RESTPostAPIGuildsMFAResult,
93+
type RESTPostAPIGuildsResult,
94+
type RESTPutAPIGuildBanJSONBody,
95+
type RESTPutAPIGuildTemplateSyncResult,
96+
type Snowflake,
9697
} from 'discord-api-types/v10';
9798

9899
export class GuildsAPI {
@@ -1229,4 +1230,15 @@ export class GuildsAPI {
12291230
body,
12301231
}) as Promise<RESTPatchAPIGuildVoiceStateCurrentMemberResult>;
12311232
}
1233+
1234+
/**
1235+
* Fetches a guild onboarding
1236+
*
1237+
* @see {@link https://discord.com/developers/docs/resources/guild#get-guild-onboarding}
1238+
* @param guildId - The id of the guild
1239+
* @param options - The options for fetching the guild onboarding
1240+
*/
1241+
public async getOnboarding(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
1242+
return this.rest.get(Routes.guildOnboarding(guildId), { signal }) as Promise<RESTGetAPIGuildOnboardingResult>;
1243+
}
12321244
}

packages/discord.js/src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ exports.GuildBan = require('./structures/GuildBan');
127127
exports.GuildChannel = require('./structures/GuildChannel');
128128
exports.GuildEmoji = require('./structures/GuildEmoji');
129129
exports.GuildMember = require('./structures/GuildMember').GuildMember;
130+
exports.GuildOnboarding = require('./structures/GuildOnboarding').GuildOnboarding;
131+
exports.GuildOnboardingPrompt = require('./structures/GuildOnboardingPrompt').GuildOnboardingPrompt;
132+
exports.GuildOnboardingPromptOption = require('./structures/GuildOnboardingPromptOption').GuildOnboardingPromptOption;
130133
exports.GuildPreview = require('./structures/GuildPreview');
131134
exports.GuildPreviewEmoji = require('./structures/GuildPreviewEmoji');
132135
exports.GuildScheduledEvent = require('./structures/GuildScheduledEvent').GuildScheduledEvent;

packages/discord.js/src/structures/Guild.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { makeURLSearchParams } = require('@discordjs/rest');
55
const { ChannelType, GuildPremiumTier, Routes, GuildFeature } = require('discord-api-types/v10');
66
const AnonymousGuild = require('./AnonymousGuild');
77
const GuildAuditLogs = require('./GuildAuditLogs');
8+
const { GuildOnboarding } = require('./GuildOnboarding');
89
const GuildPreview = require('./GuildPreview');
910
const GuildTemplate = require('./GuildTemplate');
1011
const Integration = require('./Integration');
@@ -760,6 +761,15 @@ class Guild extends AnonymousGuild {
760761
return new GuildAuditLogs(this, data);
761762
}
762763

764+
/**
765+
* Fetches the guild onboarding data for this guild.
766+
* @returns {Promise<GuildOnboarding>}
767+
*/
768+
async fetchOnboarding() {
769+
const data = await this.client.rest.get(Routes.guildOnboarding(this.id));
770+
return new GuildOnboarding(this.client, data);
771+
}
772+
763773
/**
764774
* The data for editing a guild.
765775
* @typedef {Object} GuildEditOptions
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use strict';
2+
3+
const { Collection } = require('@discordjs/collection');
4+
const Base = require('./Base');
5+
const { GuildOnboardingPrompt } = require('./GuildOnboardingPrompt');
6+
7+
/**
8+
* Represents the onboarding data of a guild.
9+
* @extends {Base}
10+
*/
11+
class GuildOnboarding extends Base {
12+
constructor(client, data) {
13+
super(client);
14+
15+
/**
16+
* The id of the guild this onboarding data is for
17+
* @type {Snowflake}
18+
*/
19+
this.guildId = data.guild_id;
20+
21+
const guild = this.guild;
22+
23+
/**
24+
* The prompts shown during onboarding and in customize community
25+
* @type {Collection<Snowflake, GuildOnboardingPrompt>}
26+
*/
27+
this.prompts = data.prompts.reduce(
28+
(prompts, prompt) => prompts.set(prompt.id, new GuildOnboardingPrompt(client, prompt, this.guildId)),
29+
new Collection(),
30+
);
31+
32+
/**
33+
* The ids of the channels that new members get opted into automatically
34+
* @type {Collection<Snowflake, GuildChannel>}
35+
*/
36+
this.defaultChannels = data.default_channel_ids.reduce(
37+
(channels, channelId) => channels.set(channelId, guild.channels.cache.get(channelId)),
38+
new Collection(),
39+
);
40+
41+
/**
42+
* Whether onboarding is enabled
43+
* @type {boolean}
44+
*/
45+
this.enabled = data.enabled;
46+
}
47+
48+
/**
49+
* The guild this onboarding is from
50+
* @type {Guild}
51+
* @readonly
52+
*/
53+
get guild() {
54+
return this.client.guilds.cache.get(this.guildId);
55+
}
56+
}
57+
58+
exports.GuildOnboarding = GuildOnboarding;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
const { Collection } = require('@discordjs/collection');
4+
const Base = require('./Base');
5+
const { GuildOnboardingPromptOption } = require('./GuildOnboardingPromptOption');
6+
7+
/**
8+
* Represents the data of a prompt of a guilds onboarding.
9+
* @extends {Base}
10+
*/
11+
class GuildOnboardingPrompt extends Base {
12+
constructor(client, data, guildId) {
13+
super(client);
14+
15+
/**
16+
* The id of the guild this onboarding prompt is from
17+
* @type {Snowflake}
18+
*/
19+
this.guildId = guildId;
20+
21+
/**
22+
* The id of the prompt
23+
* @type {Snowflake}
24+
*/
25+
this.id = data.id;
26+
27+
/**
28+
* The options available within the prompt
29+
* @type {Collection<Snowflake, GuildOnboardingPromptOption>}
30+
*/
31+
this.options = data.options.reduce(
32+
(options, option) => options.set(option.id, new GuildOnboardingPromptOption(client, option, guildId)),
33+
new Collection(),
34+
);
35+
36+
/**
37+
* The title of the prompt
38+
* @type {string}
39+
*/
40+
this.title = data.title;
41+
42+
/**
43+
* Whether users are limited to selecting one option for the prompt
44+
* @type {boolean}
45+
*/
46+
this.singleSelect = data.single_select;
47+
48+
/**
49+
* Whether the prompt is required before a user completes the onboarding flow
50+
* @type {boolean}
51+
*/
52+
this.required = data.required;
53+
54+
/**
55+
* Whether the prompt is present in the onboarding flow.
56+
* If `false`, the prompt will only appear in the Channels & Roles tab
57+
* @type {boolean}
58+
*/
59+
this.inOnboarding = data.in_onboarding;
60+
61+
/**
62+
* The type of the prompt
63+
* @type {GuildOnboardingPromptType}
64+
*/
65+
this.type = data.type;
66+
}
67+
68+
/**
69+
* The guild this onboarding prompt is from
70+
* @type {Guild}
71+
* @readonly
72+
*/
73+
get guild() {
74+
return this.client.guilds.cache.get(this.guildId);
75+
}
76+
}
77+
78+
exports.GuildOnboardingPrompt = GuildOnboardingPrompt;

0 commit comments

Comments
 (0)