mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-16 03:23:29 +01:00
Add Client.fetchInvite
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -191,6 +191,15 @@ class Client extends EventEmitter {
|
|||||||
return this.rest.methods.getUser(id);
|
return this.rest.methods.getUser(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches an invite object from an invite code.
|
||||||
|
* @param {string} code the invite code.
|
||||||
|
* @returns {Promise<Invite, Error>}
|
||||||
|
*/
|
||||||
|
fetchInvite(code) {
|
||||||
|
return this.rest.methods.getInvite(code);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a Collection, mapping Guild ID to Voice Connections.
|
* Returns a Collection, mapping Guild ID to Voice Connections.
|
||||||
* @readonly
|
* @readonly
|
||||||
|
|||||||
@@ -477,6 +477,14 @@ class RESTMethods {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInvite(code) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.rest.makeRequest('get', Constants.Endpoints.invite(code), true)
|
||||||
|
.then(invite => resolve(new Invite(this.rest.client, invite)))
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getGuildInvites(guild) {
|
getGuildInvites(guild) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('get', Constants.Endpoints.guildInvites(guild.id), true).then(inviteItems => {
|
this.rest.makeRequest('get', Constants.Endpoints.guildInvites(guild.id), true).then(inviteItems => {
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ const PartialGuildChannel = require('./PartialGuildChannel');
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an Invitation to a Guild Channel
|
* Represents an Invitation to a Guild Channel.
|
||||||
|
* <warn>The only guaranteed properties are `code`, `guild` and `channel`. Other properties can be missing.</warn>
|
||||||
*/
|
*/
|
||||||
class Invite {
|
class Invite {
|
||||||
constructor(client, data) {
|
constructor(client, data) {
|
||||||
@@ -75,11 +76,13 @@ class Invite {
|
|||||||
*/
|
*/
|
||||||
this.maxUses = data.max_uses;
|
this.maxUses = data.max_uses;
|
||||||
|
|
||||||
/**
|
if (data.inviter) {
|
||||||
* The user who created this invite
|
/**
|
||||||
* @type {User}
|
* The user who created this invite
|
||||||
*/
|
* @type {User}
|
||||||
this.inviter = this.client.dataManager.newUser(data.inviter);
|
*/
|
||||||
|
this.inviter = this.client.dataManager.newUser(data.inviter);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Channel the invite is for. If this Channel is already known, this will be a GuildChannel object.
|
* The Channel the invite is for. If this Channel is already known, this will be a GuildChannel object.
|
||||||
|
|||||||
Reference in New Issue
Block a user