Skip to content

Commit 322a2fb

Browse files
committed
feat: types and /core method
1 parent 04f0f4f commit 322a2fb

File tree

3 files changed

+118
-96
lines changed

3 files changed

+118
-96
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/typings/index.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ import {
157157
ImageFormat,
158158
GuildMemberFlags,
159159
RESTGetAPIGuildThreadsResult,
160+
RESTGetAPIGuildOnboardingResult,
161+
APIGuildOnboardingPrompt,
162+
APIGuildOnboardingPromptOption,
163+
GuildOnboardingPromptType,
160164
} from 'discord-api-types/v10';
161165
import { ChildProcess } from 'node:child_process';
162166
import { EventEmitter } from 'node:events';
@@ -1568,7 +1572,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
15681572
}
15691573

15701574
export class GuildOnboarding extends Base {
1571-
private constructor(client: Client, data: any);
1575+
private constructor(client: Client, data: RESTGetAPIGuildOnboardingResult);
15721576
public get guild(): Guild;
15731577
public guildId: Snowflake;
15741578
public prompts: Collection<Snowflake, GuildOnboardingPrompt>;
@@ -1577,7 +1581,7 @@ export class GuildOnboarding extends Base {
15771581
}
15781582

15791583
export class GuildOnboardingPrompt extends Base {
1580-
private constructor(client: Client, data: any, guildId: Snowflake);
1584+
private constructor(client: Client, data: APIGuildOnboardingPrompt, guildId: Snowflake);
15811585
public id: Snowflake;
15821586
public get guild(): Guild;
15831587
public guildId: Snowflake;
@@ -1586,11 +1590,11 @@ export class GuildOnboardingPrompt extends Base {
15861590
public singleSelect: boolean;
15871591
public required: boolean;
15881592
public inOnboarding: boolean;
1589-
public type: any;
1593+
public type: GuildOnboardingPromptType;
15901594
}
15911595

15921596
export class GuildOnboardingPromptOption extends Base {
1593-
private constructor(client: Client, data: any, guildId: Snowflake);
1597+
private constructor(client: Client, data: APIGuildOnboardingPromptOption, guildId: Snowflake);
15941598
public id: Snowflake;
15951599
public get guild(): Guild;
15961600
public guildId: Snowflake;

packages/discord.js/typings/index.test-d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ import {
171171
ApplicationCommandSubCommand,
172172
ChatInputApplicationCommandData,
173173
ApplicationCommandPermissionsManager,
174+
GuildOnboarding,
174175
} from '.';
175176
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
176177
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@@ -2267,3 +2268,8 @@ client.on('guildAuditLogEntryCreate', (auditLogEntry, guild) => {
22672268
});
22682269

22692270
expectType<Readonly<GuildMemberFlagsBitField>>(guildMember.flags);
2271+
2272+
{
2273+
const onboarding = await guild.fetchOnboarding();
2274+
expectType<GuildOnboarding>(onboarding);
2275+
}

0 commit comments

Comments
 (0)