mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Add InviteResolvable (#766)
* Add InviteResolvable Add InviteResolvable * Return data as fallback instead * Rename resolver method
This commit is contained in:
committed by
Schuyler Cebulskie
parent
77e37b62ef
commit
c4e1e4f50f
@@ -265,10 +265,11 @@ class Client extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Fetches an invite object from an invite code.
|
||||
* @param {string} code the invite code.
|
||||
* @param {InviteResolvable} invite An invite code or URL
|
||||
* @returns {Promise<Invite>}
|
||||
*/
|
||||
fetchInvite(code) {
|
||||
fetchInvite(invite) {
|
||||
const code = this.resolver.resolveInviteCode(invite);
|
||||
return this.rest.methods.getInvite(code);
|
||||
}
|
||||
|
||||
|
||||
@@ -205,6 +205,26 @@ class ClientDataResolver {
|
||||
return String(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give an invite code. This can be:
|
||||
* * An invite code
|
||||
* * An invite URL
|
||||
* @typedef {string} InviteResolvable
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves InviteResolvable to an invite code
|
||||
* @param {InviteResolvable} data The invite resolvable to resolve
|
||||
* @returns {string}
|
||||
*/
|
||||
resolveInviteCode(data) {
|
||||
const inviteRegex = /discord(?:app)?\.(?:gg|com\/invite)\/([a-z0-9]{5})/i;
|
||||
const match = inviteRegex.exec(data);
|
||||
|
||||
if (match && match[1]) return match[1];
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Data that can be resolved to give a Buffer. This can be:
|
||||
* * A Buffer
|
||||
|
||||
Reference in New Issue
Block a user