Skip to content

Commit

Permalink
feat: types and /core method
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed Jun 15, 2023
1 parent 04f0f4f commit 933514c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/api/guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ import type {
RESTPutAPIGuildBanJSONBody,
RESTPutAPIGuildTemplateSyncResult,
Snowflake,
RESTGetAPIGuildOnboardingResult,
} from 'discord-api-types/v10';

export class GuildsAPI {
Expand Down Expand Up @@ -1229,4 +1230,15 @@ export class GuildsAPI {
body,
}) as Promise<RESTPatchAPIGuildVoiceStateCurrentMemberResult>;
}

/**
* Fetches a guild onboarding
*
* @see {@link https://discord.com/developers/docs/resources/guild#get-guild-onboarding}
* @param guildId - The id of the guild
* @param options - The options for fetching the guild onboarding
*/
public async getOnboarding(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.guildOnboarding(guildId), { signal }) as Promise<RESTGetAPIGuildOnboardingResult>;
}
}
12 changes: 8 additions & 4 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ import {
ImageFormat,
GuildMemberFlags,
RESTGetAPIGuildThreadsResult,
RESTGetAPIGuildOnboardingResult,
APIGuildOnboardingPrompt,
APIGuildOnboardingPromptOption,
GuildOnboardingPromptType,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -1568,7 +1572,7 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
}

export class GuildOnboarding extends Base {
private constructor(client: Client, data: any);
private constructor(client: Client, data: RESTGetAPIGuildOnboardingResult);
public get guild(): Guild;
public guildId: Snowflake;
public prompts: Collection<Snowflake, GuildOnboardingPrompt>;
Expand All @@ -1577,7 +1581,7 @@ export class GuildOnboarding extends Base {
}

export class GuildOnboardingPrompt extends Base {
private constructor(client: Client, data: any, guildId: Snowflake);
private constructor(client: Client, data: APIGuildOnboardingPrompt, guildId: Snowflake);
public id: Snowflake;
public get guild(): Guild;
public guildId: Snowflake;
Expand All @@ -1586,11 +1590,11 @@ export class GuildOnboardingPrompt extends Base {
public singleSelect: boolean;
public required: boolean;
public inOnboarding: boolean;
public type: any;
public type: GuildOnboardingPromptType;
}

export class GuildOnboardingPromptOption extends Base {
private constructor(client: Client, data: any, guildId: Snowflake);
private constructor(client: Client, data: APIGuildOnboardingPromptOption, guildId: Snowflake);
public id: Snowflake;
public get guild(): Guild;
public guildId: Snowflake;
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ import {
ApplicationCommandSubCommand,
ChatInputApplicationCommandData,
ApplicationCommandPermissionsManager,
GuildOnboarding,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -2267,3 +2268,8 @@ client.on('guildAuditLogEntryCreate', (auditLogEntry, guild) => {
});

expectType<Readonly<GuildMemberFlagsBitField>>(guildMember.flags);

{
const onboarding = await guild.fetchOnboarding();
expectType<GuildOnboarding>(onboarding);
}

0 comments on commit 933514c

Please sign in to comment.