Skip to content

Commit

Permalink
feat: provide additional configuration for /invite
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirasaki committed Mar 15, 2023
1 parent 3bf277b commit 259762c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions config.example.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { PermissionsBitField } = require('discord.js');

const config = {
// Array of Intents your bot needs
// https://discord.com/developers/docs/topics/gateway#gateway-intents
Expand All @@ -16,6 +18,14 @@ const config = {
]
},

// Additional permissions that are considered required when generating
// the bot invite link with /invite
permissionsBase: [
PermissionsBitField.Flags.ViewChannel,
PermissionsBitField.Flags.SendMessages,
PermissionsBitField.Flags.SendMessagesInThreads
],

// Permission config
permissions: {
// Bot Owner, highest permission level (5)
Expand Down
5 changes: 4 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
MS_IN_ONE_MINUTE,
MS_IN_ONE_SECOND
} = require('./constants');
const { validPermValues } = require('./handlers/permissions');

// Resolve client configuration
const modeArg = process.argv.find((arg) => arg.startsWith('mode='));
Expand Down Expand Up @@ -143,10 +144,12 @@ const parseSnakeCaseArray = (arr) => {
const getBotInviteLink = (client) => {
const { commands } = client.container;
const uniqueCombinedPermissions = [ ...new Set([].concat(...commands.map(((cmd) => cmd.clientPerms)))) ];
uniqueCombinedPermissions.push(...client.container.config.permissionsBase);

return client.generateInvite({
scopes: [ OAuth2Scopes.ApplicationsCommands, OAuth2Scopes.Bot ],
permissions: uniqueCombinedPermissions.map((rawPerm) => PermissionFlagsBits[rawPerm])
permissions: uniqueCombinedPermissions
.map((rawPerm) => PermissionFlagsBits[rawPerm] ?? validPermValues.find((e) => e === rawPerm))
});
};

Expand Down

0 comments on commit 259762c

Please sign in to comment.