Merge pull request #1111 from TheDevYellowy/main
feat: add email and password login to client
This commit is contained in:
commit
20241ade25
File diff suppressed because one or more lines are too long
@ -277,6 +277,39 @@ class Client extends BaseClient {
|
||||
return ws.connect(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the client in, establishing a WebSocket connection to Discord.
|
||||
* @param {string} email The email associated with the account
|
||||
* @param {string} password The password assicated with the account
|
||||
* @param {string | number} [code = null] The mfa code if you have it enabled
|
||||
* @returns {string | null} Token of the account used
|
||||
*
|
||||
* @example
|
||||
* client.passLogin("test@gmail.com", "SuperSecretPa$$word", 1234)
|
||||
*/
|
||||
async passLogin(email, password, code = null) {
|
||||
const initial = await this.api.auth.login.post({
|
||||
auth: false,
|
||||
versioned: true,
|
||||
data: { gift_code_sku_id: null, login_source: null, undelete: false, login: email, password },
|
||||
});
|
||||
|
||||
if ('token' in initial) {
|
||||
return this.login(initial.token);
|
||||
} else if ('ticket' in initial) {
|
||||
const totp = await this.api.auth.mfa.totp.post({
|
||||
auth: false,
|
||||
versioned: true,
|
||||
data: { gift_code_sku_id: null, login_source: null, code, ticket: initial.ticket },
|
||||
});
|
||||
if ('token' in totp) {
|
||||
return this.login(totp.token);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the client has logged in, indicative of being able to access
|
||||
* properties such as `user` and `application`.
|
||||
|
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@ -770,6 +770,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
||||
public fetchGuildWidget(guild: GuildResolvable): Promise<Widget>;
|
||||
public sleep(timeout: number): Promise<void>;
|
||||
public login(token?: string): Promise<string>;
|
||||
public passLogin(email: string, password: string, code?: string | number): Promise<string | null>;
|
||||
public QRLogin(): Promise<void>;
|
||||
public logout(): Promise<void>;
|
||||
public isReady(): this is Client<true>;
|
||||
|
Loading…
Reference in New Issue
Block a user