Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Client): add InviteGenerationOptions#additionalScopes #5215

Merged
merged 9 commits into from Feb 10, 2021
14 changes: 13 additions & 1 deletion src/client/Client.js
Expand Up @@ -17,7 +17,7 @@ const Invite = require('../structures/Invite');
const VoiceRegion = require('../structures/VoiceRegion');
const Webhook = require('../structures/Webhook');
const Collection = require('../util/Collection');
const { Events, DefaultOptions } = require('../util/Constants');
const { Events, DefaultOptions, InviteScopes } = require('../util/Constants');
const DataResolver = require('../util/DataResolver');
const Intents = require('../util/Intents');
const Permissions = require('../util/Permissions');
Expand Down Expand Up @@ -377,6 +377,7 @@ class Client extends BaseClient {
* @property {PermissionResolvable} [permissions] Permissions to request
* @property {GuildResolvable} [guild] Guild to preselect
* @property {boolean} [disableGuildSelect] Whether to disable the guild selection
* @property {InviteScope[]} [additionalScopes] Whether any additional scopes should be requested
*/

/**
Expand Down Expand Up @@ -414,6 +415,17 @@ class Client extends BaseClient {
query.set('guild_id', guildID);
}

if (options.additionalScopes) {
const scopes = options.additionalScopes;
scopes.forEach(scope => {
if (!InviteScopes.includes(scope)) {
throw new TypeError('INVALID_TYPE', 'additionalScopes', 'Array of Invite Scopes', true);
}
});
ckohen marked this conversation as resolved.
Show resolved Hide resolved
scopes.unshift('bot');
query.set('scope', scopes.join(' '));
ckohen marked this conversation as resolved.
Show resolved Hide resolved
}

return `${this.options.http.api}${this.api.oauth2.authorize}?${query}`;
}

Expand Down
28 changes: 28 additions & 0 deletions src/util/Constants.js
Expand Up @@ -378,6 +378,34 @@ exports.WSEvents = keyMirror([
'WEBHOOKS_UPDATE',
]);

/**
* A valid scope to request when generating an invite link.
* <warn>Scopes that require whitelist are not considered valid for this generator</warn>
* * `applications.builds.read`: allows reading build data for a users applications
* * `applications.commands`: allows this bot to create commands in the server
* * `connections`: makes the endpoint for getting a users connections available
ckohen marked this conversation as resolved.
Show resolved Hide resolved
* * `email`: allows the `/users/@me` endpoint return with an email
* * `identify`: allows the `/users/@me` endpoint without an email
* * `guilds`: makes the `/users/@me/guilds` endpoint available for a user
* * `guilds.join`: allows the bot to join the user to any guild it is in using Guild#addMember
* * `gdm.join`: allows joining the user to a group dm
* * `webhook.incoming`: generates a webhook to a channel
* @typedef {string} InviteScope
*/
exports.InviteScopes = [
'applications.builds.read',
'applications.commands',
'applications.entitlements',
'applications.store.update',
'connections',
'email',
'identity',
'guilds',
'guilds.join',
'gdm.join',
'webhook.incoming',
];

/**
* The type of a message, e.g. `DEFAULT`. Here are the available types:
* * DEFAULT
Expand Down
15 changes: 15 additions & 0 deletions typings/index.d.ts
Expand Up @@ -513,6 +513,7 @@ declare module 'discord.js' {
SMALL: 1;
BIG: 2;
};
InviteScopes: InviteScope[];
MessageTypes: MessageType[];
SystemMessageTypes: SystemMessageType[];
ActivityTypes: ActivityType[];
Expand Down Expand Up @@ -2729,6 +2730,7 @@ declare module 'discord.js' {
permissions?: PermissionResolvable;
guild?: GuildResolvable;
disableGuildSelect?: boolean;
additionalScopes?: InviteScope[];
}

interface InviteOptions {
Expand All @@ -2741,6 +2743,19 @@ declare module 'discord.js' {

type InviteResolvable = string;

type InviteScope =
| 'applications.builds.read'
| 'applications.commands'
| 'applications.entitlements'
| 'applications.store.update'
| 'connections'
| 'email'
| 'identity'
| 'guilds'
| 'guilds.join'
| 'gdm.join'
| 'webhook.incoming';

type GuildTemplateResolvable = string;

type MembershipStates = 'INVITED' | 'ACCEPTED';
Expand Down