mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
add an invite generator (#993)
* add an invite generator * `number |= null` is safe, so we can simplify this * Update Client.js * aaaaaa
This commit is contained in:
@@ -343,6 +343,29 @@ class Client extends EventEmitter {
|
|||||||
return this.rest.methods.getMyApplication();
|
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.
|
* Sets a timeout that will be automatically cancelled if the client is destroyed.
|
||||||
* @param {Function} fn Function to execute
|
* @param {Function} fn Function to execute
|
||||||
|
|||||||
@@ -190,6 +190,19 @@ class ClientDataResolver {
|
|||||||
return permission;
|
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:
|
* Data that can be resolved to give a string. This can be:
|
||||||
* * A string
|
* * A string
|
||||||
|
|||||||
Reference in New Issue
Block a user