mirror of
https://github.com/danbulant/discord.js
synced 2026-06-09 01:31:29 +00:00
add clientuser acceptinvite (#1081)
* add clientuser acceptinvite * Update RESTMethods.js * Update ClientUser.js * Update ClientUser.js * Update RESTMethods.js
This commit is contained in:
parent
7f4846c826
commit
48be401330
2 changed files with 27 additions and 0 deletions
|
|
@ -715,6 +715,25 @@ class RESTMethods {
|
||||||
setNote(user, note) {
|
setNote(user, note) {
|
||||||
return this.rest.makeRequest('put', Constants.Endpoints.note(user.id), true, { note }).then(() => user);
|
return this.rest.makeRequest('put', Constants.Endpoints.note(user.id), true, { note }).then(() => user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
acceptInvite(code) {
|
||||||
|
if (code.id) code = code.id;
|
||||||
|
return new Promise((resolve, reject) =>
|
||||||
|
this.rest.makeRequest('post', Constants.Endpoints.invite(code), true).then((res) => {
|
||||||
|
const handler = guild => {
|
||||||
|
if (guild.id === res.id) {
|
||||||
|
resolve(guild);
|
||||||
|
this.client.removeListener('guildCreate', handler);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.client.on('guildCreate', handler);
|
||||||
|
this.client.setTimeout(() => {
|
||||||
|
this.client.removeListener('guildCreate', handler);
|
||||||
|
reject(new Error('Accepting invite timed out'));
|
||||||
|
}, 120e3);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RESTMethods;
|
module.exports = RESTMethods;
|
||||||
|
|
|
||||||
|
|
@ -297,6 +297,14 @@ class ClientUser extends User {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Invite|string} invite Invite or code to accept
|
||||||
|
* @returns {Promise<Guild>} Joined guild
|
||||||
|
*/
|
||||||
|
acceptInvite(invite) {
|
||||||
|
return this.client.rest.methods.acceptInvite(invite);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ClientUser;
|
module.exports = ClientUser;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue