feat: acceptInvite options
This commit is contained in:
parent
5758f0fdbf
commit
4e909fd889
@ -507,14 +507,22 @@ class Client extends BaseClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for {@link Client#acceptInvite}.
|
||||||
|
* @typedef {Object} AcceptInviteOptions
|
||||||
|
* @property {boolean} [bypassOnboarding=true] Whether to bypass onboarding
|
||||||
|
* @property {boolean} [bypassVerify=true] Whether to bypass rule screening
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join this Guild using this invite
|
* Join this Guild using this invite
|
||||||
* @param {InviteResolvable} invite Invite code or URL
|
* @param {InviteResolvable} invite Invite code or URL
|
||||||
|
* @param {AcceptInviteOptions} [options={ bypassOnboarding: true, bypassVerify: true }] Options
|
||||||
* @returns {Promise<Guild|DMChannel|GroupDMChannel>}
|
* @returns {Promise<Guild|DMChannel|GroupDMChannel>}
|
||||||
* @example
|
* @example
|
||||||
* await client.acceptInvite('https://discord.gg/genshinimpact')
|
* await client.acceptInvite('https://discord.gg/genshinimpact', { bypassOnboarding: true, bypassVerify: true })
|
||||||
*/
|
*/
|
||||||
async acceptInvite(invite) {
|
async acceptInvite(invite, options = { bypassOnboarding: true, bypassVerify: true }) {
|
||||||
const code = DataResolver.resolveInviteCode(invite);
|
const code = DataResolver.resolveInviteCode(invite);
|
||||||
if (!code) throw new Error('INVITE_RESOLVE_CODE');
|
if (!code) throw new Error('INVITE_RESOLVE_CODE');
|
||||||
const i = await this.fetchInvite(code);
|
const i = await this.fetchInvite(code);
|
||||||
@ -539,7 +547,7 @@ class Client extends BaseClient {
|
|||||||
if (i.guild?.id) {
|
if (i.guild?.id) {
|
||||||
const onboardingData = await this.api.guilds[i.guild?.id].onboarding.get();
|
const onboardingData = await this.api.guilds[i.guild?.id].onboarding.get();
|
||||||
// Onboarding
|
// Onboarding
|
||||||
if (onboardingData.enabled) {
|
if (onboardingData.enabled && options.bypassOnboarding) {
|
||||||
const prompts = onboardingData.prompts.filter(o => o.in_onboarding);
|
const prompts = onboardingData.prompts.filter(o => o.in_onboarding);
|
||||||
if (prompts.length) {
|
if (prompts.length) {
|
||||||
const onboarding_prompts_seen = {};
|
const onboarding_prompts_seen = {};
|
||||||
@ -567,7 +575,7 @@ class Client extends BaseClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Read rule
|
// Read rule
|
||||||
if (data.show_verification_form) {
|
if (data.show_verification_form && options.bypassVerify) {
|
||||||
// Check Guild
|
// Check Guild
|
||||||
if (i.guild.verificationLevel == 'VERY_HIGH' && !this.user.phone) {
|
if (i.guild.verificationLevel == 'VERY_HIGH' && !this.user.phone) {
|
||||||
this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Cannot bypass verify (Phone required)`);
|
this.emit(Events.DEBUG, `[Invite > Guild ${i.guild?.id}] Cannot bypass verify (Phone required)`);
|
||||||
|
7
typings/index.d.ts
vendored
7
typings/index.d.ts
vendored
@ -807,7 +807,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
/** @deprecated Use {@link Sweepers#sweepMessages} instead */
|
/** @deprecated Use {@link Sweepers#sweepMessages} instead */
|
||||||
public sweepMessages(lifetime?: number): number;
|
public sweepMessages(lifetime?: number): number;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
public acceptInvite(invite: InviteResolvable): Promise<Guild | DMChannel | GroupDMChannel>;
|
public acceptInvite(invite: InviteResolvable, options?: AcceptInviteOptions): Promise<Guild | DMChannel | GroupDMChannel>;
|
||||||
public redeemNitro(nitro: string, channel?: TextChannelResolvable, paymentSourceId?: Snowflake): Promise<any>;
|
public redeemNitro(nitro: string, channel?: TextChannelResolvable, paymentSourceId?: Snowflake): Promise<any>;
|
||||||
public authorizeURL(url: string, options?: OAuth2AuthorizeOptions): Promise<any>;
|
public authorizeURL(url: string, options?: OAuth2AuthorizeOptions): Promise<any>;
|
||||||
|
|
||||||
@ -836,6 +836,11 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
public removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof ClientEvents>): this;
|
public removeAllListeners<S extends string | symbol>(event?: Exclude<S, keyof ClientEvents>): this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AcceptInviteOptions {
|
||||||
|
bypassOnboarding: boolean;
|
||||||
|
bypassVerify: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface OAuth2AuthorizeOptions {
|
export interface OAuth2AuthorizeOptions {
|
||||||
guild_id?: Snowflake;
|
guild_id?: Snowflake;
|
||||||
permissions?: PermissionResolvable;
|
permissions?: PermissionResolvable;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user