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
|
||||
* @param {InviteResolvable} invite Invite code or URL
|
||||
* @param {AcceptInviteOptions} [options={ bypassOnboarding: true, bypassVerify: true }] Options
|
||||
* @returns {Promise<Guild|DMChannel|GroupDMChannel>}
|
||||
* @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);
|
||||
if (!code) throw new Error('INVITE_RESOLVE_CODE');
|
||||
const i = await this.fetchInvite(code);
|
||||
@ -539,7 +547,7 @@ class Client extends BaseClient {
|
||||
if (i.guild?.id) {
|
||||
const onboardingData = await this.api.guilds[i.guild?.id].onboarding.get();
|
||||
// Onboarding
|
||||
if (onboardingData.enabled) {
|
||||
if (onboardingData.enabled && options.bypassOnboarding) {
|
||||
const prompts = onboardingData.prompts.filter(o => o.in_onboarding);
|
||||
if (prompts.length) {
|
||||
const onboarding_prompts_seen = {};
|
||||
@ -567,7 +575,7 @@ class Client extends BaseClient {
|
||||
}
|
||||
}
|
||||
// Read rule
|
||||
if (data.show_verification_form) {
|
||||
if (data.show_verification_form && options.bypassVerify) {
|
||||
// Check Guild
|
||||
if (i.guild.verificationLevel == 'VERY_HIGH' && !this.user.phone) {
|
||||
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 */
|
||||
public sweepMessages(lifetime?: number): number;
|
||||
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 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;
|
||||
}
|
||||
|
||||
export interface AcceptInviteOptions {
|
||||
bypassOnboarding: boolean;
|
||||
bypassVerify: boolean;
|
||||
}
|
||||
|
||||
export interface OAuth2AuthorizeOptions {
|
||||
guild_id?: Snowflake;
|
||||
permissions?: PermissionResolvable;
|
||||
|
Loading…
x
Reference in New Issue
Block a user