diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js
index 166f8c3e3..d895922a7 100644
--- a/src/client/rest/RESTMethods.js
+++ b/src/client/rest/RESTMethods.js
@@ -212,14 +212,14 @@ class RESTMethods {
);
}
- updateCurrentUser(_data) {
+ updateCurrentUser(_data, password) {
const user = this.rest.client.user;
const data = {};
data.username = _data.username || user.username;
data.avatar = this.rest.client.resolver.resolveBase64(_data.avatar) || user.avatar;
if (!user.bot) {
data.email = _data.email || user.email;
- data.password = this.rest.client.password;
+ data.password = password;
if (_data.new_password) data.new_password = _data.newPassword;
}
return this.rest.makeRequest('patch', Constants.Endpoints.me, true, data).then(newData =>
diff --git a/src/structures/ClientUser.js b/src/structures/ClientUser.js
index 45de13a6c..66b9504e9 100644
--- a/src/structures/ClientUser.js
+++ b/src/structures/ClientUser.js
@@ -54,6 +54,7 @@ class ClientUser extends User {
* Changing usernames in Discord is heavily rate limited, with only 2 requests
* every hour. Use this sparingly!
* @param {string} username The new username
+ * @param {string} [password] Current password (only for user accounts)
* @returns {Promise}
* @example
* // set username
@@ -61,38 +62,40 @@ class ClientUser extends User {
* .then(user => console.log(`My new username is ${user.username}`))
* .catch(console.error);
*/
- setUsername(username) {
- return this.client.rest.methods.updateCurrentUser({ username });
+ setUsername(username, password) {
+ 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
- * email here.
- * @param {string} email The new email
+ * Changes the email for the client user's account.
+ * This is only available when using a user account.
+ * @param {string} email New email to change to
+ * @param {string} password Current password
* @returns {Promise}
* @example
* // 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}`))
* .catch(console.error);
*/
- setEmail(email) {
- return this.client.rest.methods.updateCurrentUser({ email });
+ setEmail(email, password) {
+ 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
- * password here.
- * @param {string} password The new password
+ * Changes the password for the client user's account.
+ * This is only available when using a user account.
+ * @param {string} newPassword New password to change to
+ * @param {string} oldPassword Current password
* @returns {Promise}
* @example
* // 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!'))
* .catch(console.error);
*/
- setPassword(password) {
- return this.client.rest.methods.updateCurrentUser({ password });
+ setPassword(newPassword, oldPassword) {
+ return this.client.rest.methods.updateCurrentUser({ password: newPassword }, oldPassword);
}
/**
diff --git a/src/structures/User.js b/src/structures/User.js
index 7c19bef1e..9b3155ebd 100644
--- a/src/structures/User.js
+++ b/src/structures/User.js
@@ -61,6 +61,7 @@ class User {
for (const prop of ['id', 'username', 'discriminator', 'avatar', 'bot']) {
if (typeof data[prop] !== 'undefined') this[prop] = data[prop];
}
+ if (data.token) this.client.token = data.token;
}
/**