mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Update User#setEmail/setPassword/setUsername (#991)
* fix some things with user updates and tokens and such * fix stupid * Update ClientUser.js * Update ClientUser.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
84954c8860
commit
cecb0aee02
@@ -212,14 +212,14 @@ class RESTMethods {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCurrentUser(_data) {
|
updateCurrentUser(_data, password) {
|
||||||
const user = this.rest.client.user;
|
const user = this.rest.client.user;
|
||||||
const data = {};
|
const data = {};
|
||||||
data.username = _data.username || user.username;
|
data.username = _data.username || user.username;
|
||||||
data.avatar = this.rest.client.resolver.resolveBase64(_data.avatar) || user.avatar;
|
data.avatar = this.rest.client.resolver.resolveBase64(_data.avatar) || user.avatar;
|
||||||
if (!user.bot) {
|
if (!user.bot) {
|
||||||
data.email = _data.email || user.email;
|
data.email = _data.email || user.email;
|
||||||
data.password = this.rest.client.password;
|
data.password = password;
|
||||||
if (_data.new_password) data.new_password = _data.newPassword;
|
if (_data.new_password) data.new_password = _data.newPassword;
|
||||||
}
|
}
|
||||||
return this.rest.makeRequest('patch', Constants.Endpoints.me, true, data).then(newData =>
|
return this.rest.makeRequest('patch', Constants.Endpoints.me, true, data).then(newData =>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class ClientUser extends User {
|
|||||||
* <info>Changing usernames in Discord is heavily rate limited, with only 2 requests
|
* <info>Changing usernames in Discord is heavily rate limited, with only 2 requests
|
||||||
* every hour. Use this sparingly!</info>
|
* every hour. Use this sparingly!</info>
|
||||||
* @param {string} username The new username
|
* @param {string} username The new username
|
||||||
|
* @param {string} [password] Current password (only for user accounts)
|
||||||
* @returns {Promise<ClientUser>}
|
* @returns {Promise<ClientUser>}
|
||||||
* @example
|
* @example
|
||||||
* // set username
|
* // set username
|
||||||
@@ -61,38 +62,40 @@ class ClientUser extends User {
|
|||||||
* .then(user => console.log(`My new username is ${user.username}`))
|
* .then(user => console.log(`My new username is ${user.username}`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
setUsername(username) {
|
setUsername(username, password) {
|
||||||
return this.client.rest.methods.updateCurrentUser({ username });
|
return this.client.rest.methods.updateCurrentUser({ username }, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this user is a "self bot" or logged in using a normal user's details (which should be avoided), you can set the
|
* Changes the email for the client user's account.
|
||||||
* email here.
|
* <warn>This is only available when using a user account.</warn>
|
||||||
* @param {string} email The new email
|
* @param {string} email New email to change to
|
||||||
|
* @param {string} password Current password
|
||||||
* @returns {Promise<ClientUser>}
|
* @returns {Promise<ClientUser>}
|
||||||
* @example
|
* @example
|
||||||
* // set email
|
* // set email
|
||||||
* client.user.setEmail('bob@gmail.com')
|
* client.user.setEmail('bob@gmail.com', 'some amazing password 123')
|
||||||
* .then(user => console.log(`My new email is ${user.email}`))
|
* .then(user => console.log(`My new email is ${user.email}`))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
setEmail(email) {
|
setEmail(email, password) {
|
||||||
return this.client.rest.methods.updateCurrentUser({ email });
|
return this.client.rest.methods.updateCurrentUser({ email }, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this user is a "self bot" or logged in using a normal user's details (which should be avoided), you can set the
|
* Changes the password for the client user's account.
|
||||||
* password here.
|
* <warn>This is only available when using a user account.</warn>
|
||||||
* @param {string} password The new password
|
* @param {string} newPassword New password to change to
|
||||||
|
* @param {string} oldPassword Current password
|
||||||
* @returns {Promise<ClientUser>}
|
* @returns {Promise<ClientUser>}
|
||||||
* @example
|
* @example
|
||||||
* // set password
|
* // set password
|
||||||
* client.user.setPassword('password123')
|
* client.user.setPassword('some new amazing password 456', 'some amazing password 123')
|
||||||
* .then(user => console.log('New password set!'))
|
* .then(user => console.log('New password set!'))
|
||||||
* .catch(console.error);
|
* .catch(console.error);
|
||||||
*/
|
*/
|
||||||
setPassword(password) {
|
setPassword(newPassword, oldPassword) {
|
||||||
return this.client.rest.methods.updateCurrentUser({ password });
|
return this.client.rest.methods.updateCurrentUser({ password: newPassword }, oldPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class User {
|
|||||||
for (const prop of ['id', 'username', 'discriminator', 'avatar', 'bot']) {
|
for (const prop of ['id', 'username', 'discriminator', 'avatar', 'bot']) {
|
||||||
if (typeof data[prop] !== 'undefined') this[prop] = data[prop];
|
if (typeof data[prop] !== 'undefined') this[prop] = data[prop];
|
||||||
}
|
}
|
||||||
|
if (data.token) this.client.token = data.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user