diff --git a/src/client/Client.js b/src/client/Client.js index d01125b..663c4cc 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -418,6 +418,19 @@ class Client extends BaseClient { } } + /** + * Switch the user + * @param {string | switchUserOptions} options Either the token or an object with the username, password, and mfaCode + */ + async switchUser(options) { + await this.logout(); + if (typeof options == 'string') { + await this.login(options); + } else { + await this.normalLogin(options.username, options.password, options.mfaCode); + } + } + /** * Sign in with the QR code on your phone. * @param {boolean} debug Debug mode diff --git a/typings/index.d.ts b/typings/index.d.ts index 4899d86..f1844f1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -868,6 +868,12 @@ export interface remoteAuthConfrim { no(): Promise; } +export interface switchUserOptions { + username: string; + password: string; + mfaCode?: number; +} + export class Client extends BaseClient { public constructor(options?: ClientOptions); /* Bug report by Mavri#0001 [721347809667973141] */ private actions: unknown; @@ -915,6 +921,7 @@ export class Client extends BaseClient { public generateInvite(options?: InviteGenerationOptions): string; public login(token?: string): Promise; public normalLogin(username: string, password?: string, mfaCode?: string): Promise; + public switchUser(options: string | switchUserOptions): void; public QRLogin(debug?: boolean): DiscordAuthWebsocket; public remoteAuth(url: string, forceAccept?: boolean): Promise; public createToken(): Promise; @@ -5314,8 +5321,8 @@ export type CacheConstructors = { // Narrowing the type of `manager.name` doesn't propagate type information to `holds` and the return type. export type CacheFactory = ( manager: CacheConstructors[keyof Caches], - holds: Caches[typeof manager['name']][1], -) => typeof manager['prototype'] extends DataManager ? Collection : never; + holds: Caches[(typeof manager)['name']][1], +) => (typeof manager)['prototype'] extends DataManager ? Collection : never; export type CacheWithLimitsOptions = { [K in keyof Caches]?: Caches[K][0]['prototype'] extends DataManager