This commit is contained in:
Travis CI 2016-12-20 23:38:29 +00:00
parent 9bb44cf0f8
commit 01a53d242d
2 changed files with 40 additions and 4 deletions

View file

@ -10905,6 +10905,19 @@ class ClientDataResolver {
return permission;
}
/**
* Turn an array of permissions into a valid discord permission bitfield
* @param {Array} permissions An array of permissions as strings or permissions numbers (see resolvePermission)
* @returns {number}
*/
resolvePermissions(permissions) {
let bitfield = 0;
for (const permission of permissions) {
bitfield |= this.resolvePermission(permission);
}
return bitfield;
}
/**
* Data that can be resolved to give a string. This can be:
* * A string
@ -11517,6 +11530,29 @@ class Client extends EventEmitter {
return this.rest.methods.getMyApplication();
}
/**
* Generate an invite link for your bot
* @param {Array|number} [permissions] An array of permissions to request
* @returns {Promise<string>} The invite link
* @example
* client.generateInvite(['SEND_MESSAGES', 'MANAGE_GUILD', 'MENTION_EVERYONE'])
* .then(link => {
* console.log(link);
* });
*/
generateInvite(permissions) {
if (permissions) {
if (permissions instanceof Array) {
permissions = this.resolver.resolvePermissions(permissions);
}
} else {
permissions = 0;
}
return this.fetchApplication().then(application =>
`https://discordapp.com/oauth2/authorize?client_id=${application.id}&permissions=${permissions}&scope=bot`
);
}
/**
* Sets a timeout that will be automatically cancelled if the client is destroyed.
* @param {Function} fn Function to execute

File diff suppressed because one or more lines are too long