feat(Guild): Add new parameter to setVanityCode method to allow entering MFA code (#1294)
This commit is contained in:
@@ -282,14 +282,14 @@ class Client extends BaseClient {
|
|||||||
* Logs the client in, establishing a WebSocket connection to Discord.
|
* Logs the client in, establishing a WebSocket connection to Discord.
|
||||||
* @param {string} email The email associated with the account
|
* @param {string} email The email associated with the account
|
||||||
* @param {string} password The password assicated 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
|
* @param {string|number} [mfaCode = null] The mfa code if you have it enabled
|
||||||
* @returns {string | null} Token of the account used
|
* @returns {string | null} Token of the account used
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* client.passLogin("test@gmail.com", "SuperSecretPa$$word", 1234)
|
* client.passLogin("test@gmail.com", "SuperSecretPa$$word", 1234)
|
||||||
* @deprecated This method will not be updated until I find the most convenient way to implement MFA.
|
* @deprecated This method will not be updated until I find the most convenient way to implement MFA.
|
||||||
*/
|
*/
|
||||||
async passLogin(email, password, code = null) {
|
async passLogin(email, password, mfaCode = null) {
|
||||||
const initial = await this.api.auth.login.post({
|
const initial = await this.api.auth.login.post({
|
||||||
auth: false,
|
auth: false,
|
||||||
versioned: true,
|
versioned: true,
|
||||||
@@ -302,7 +302,7 @@ class Client extends BaseClient {
|
|||||||
const totp = await this.api.auth.mfa.totp.post({
|
const totp = await this.api.auth.mfa.totp.post({
|
||||||
auth: false,
|
auth: false,
|
||||||
versioned: true,
|
versioned: true,
|
||||||
data: { gift_code_sku_id: null, login_source: null, code, ticket: initial.ticket },
|
data: { gift_code_sku_id: null, login_source: null, code: mfaCode, ticket: initial.ticket },
|
||||||
});
|
});
|
||||||
if ('token' in totp) {
|
if ('token' in totp) {
|
||||||
return this.login(totp.token);
|
return this.login(totp.token);
|
||||||
|
|||||||
@@ -1528,19 +1528,23 @@ class Guild extends AnonymousGuild {
|
|||||||
* Set the vanity URL to this guild.
|
* Set the vanity URL to this guild.
|
||||||
* Resolves with an object containing the vanity URL invite code and the use count.
|
* Resolves with an object containing the vanity URL invite code and the use count.
|
||||||
* @param {string} [code=''] Vanity URL code
|
* @param {string} [code=''] Vanity URL code
|
||||||
|
* @param {string|number} [mfaCode = null] Two-factor authentication code
|
||||||
|
* After you enter the mfaCode, you will receive a `__Secure-recent_mfa` cookie, which is valid for about
|
||||||
|
* 5 minutes, during which you won't need to enter MFA again.
|
||||||
* @returns {Promise<Vanity>}
|
* @returns {Promise<Vanity>}
|
||||||
* @example
|
* @example
|
||||||
* // Set invite code
|
* // Set invite code
|
||||||
* guild.setVanityCode('elysia')
|
* guild.setVanityCode('elysia', '123456')
|
||||||
* .then(res => {
|
* .then(res => {
|
||||||
* console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`);
|
* console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`);
|
||||||
* })
|
* })
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
async setVanityCode(code = '') {
|
async setVanityCode(code = '', mfaCode = null) {
|
||||||
if (typeof code !== 'string') throw new TypeError('INVALID_VANITY_URL_CODE');
|
if (typeof code !== 'string') throw new TypeError('INVALID_VANITY_URL_CODE');
|
||||||
const data = await this.client.api.guilds(this.id, 'vanity-url').patch({
|
const data = await this.client.api.guilds(this.id, 'vanity-url').patch({
|
||||||
data: { code },
|
data: { code },
|
||||||
|
mfaCode,
|
||||||
});
|
});
|
||||||
this.vanityURLCode = data.code;
|
this.vanityURLCode = data.code;
|
||||||
this.vanityURLUses = data.uses;
|
this.vanityURLUses = data.uses;
|
||||||
|
|||||||
4
typings/index.d.ts
vendored
4
typings/index.d.ts
vendored
@@ -777,7 +777,7 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
|
|||||||
public sleep(timeout: number): Promise<void>;
|
public sleep(timeout: number): Promise<void>;
|
||||||
public login(token?: string): Promise<string>;
|
public login(token?: string): Promise<string>;
|
||||||
/** @deprecated This method will not be updated until I find the most convenient way to implement MFA. */
|
/** @deprecated This method will not be updated until I find the most convenient way to implement MFA. */
|
||||||
public passLogin(email: string, password: string, code?: string | number): Promise<string | null>;
|
public passLogin(email: string, password: string, mfaCode?: string | number): Promise<string | null>;
|
||||||
public QRLogin(): Promise<void>;
|
public QRLogin(): Promise<void>;
|
||||||
public logout(): Promise<void>;
|
public logout(): Promise<void>;
|
||||||
public isReady(): this is Client<true>;
|
public isReady(): this is Client<true>;
|
||||||
@@ -1493,7 +1493,7 @@ export class Guild extends AnonymousGuild {
|
|||||||
reason?: string,
|
reason?: string,
|
||||||
): Promise<this>;
|
): Promise<this>;
|
||||||
public topEmojis(): Promise<Collection<number, GuildEmoji>>;
|
public topEmojis(): Promise<Collection<number, GuildEmoji>>;
|
||||||
public setVanityCode(code?: string): Promise<this>;
|
public setVanityCode(code?: string, mfaCode?: string | number): Promise<this>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'> {
|
export class GuildAuditLogs<T extends GuildAuditLogsResolvable = 'ALL'> {
|
||||||
|
|||||||
Reference in New Issue
Block a user