|
| 1 | +--- |
| 2 | +title: CommandKit setup |
| 3 | +description: A simple overview of how to set up CommandKit with all the available options. |
| 4 | +--- |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | + |
| 9 | +# CommandKit Setup |
| 10 | + |
| 11 | +This is a simple overview of how to set up CommandKit with all the available options. You’d usually set this up in your entry file (e.g. `index.js`) where you have access to your Discord.js client object. |
| 12 | + |
| 13 | +<Tabs> |
| 14 | + <TabItem value='cjs' label='CommonJS' default> |
| 15 | + ```js title="src/index.js" {2, 13-23} |
| 16 | + const { Client, GatewayIntentBits } = require('discord.js'); |
| 17 | + const { CommandKit } = require('commandkit'); |
| 18 | + const path = require('path'); |
| 19 | + |
| 20 | + const client = new Client({ |
| 21 | + intents: [ |
| 22 | + GatewayIntentBits.Guilds, |
| 23 | + GatewayIntentBits.GuildMessages, |
| 24 | + GatewayIntentBits.MessageContent, |
| 25 | + ], |
| 26 | + }); |
| 27 | + |
| 28 | + new CommandKit({ |
| 29 | + client, |
| 30 | + commandsPath: path.join(__dirname, 'commands'), |
| 31 | + eventsPath: path.join(__dirname, 'events'), |
| 32 | + validationsPath: path.join(__dirname, 'validations'), |
| 33 | + devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'], |
| 34 | + devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'], |
| 35 | + devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'], |
| 36 | + skipBuiltInValidations: true, |
| 37 | + bulkRegister: true, |
| 38 | + }); |
| 39 | + |
| 40 | + client.login('YOUR_TOKEN_HERE'); |
| 41 | + ``` |
| 42 | + </TabItem> |
| 43 | + <TabItem value='esm' label='ESM'> |
| 44 | + ```js title="src/index.js" {2, 16-26} |
| 45 | + import { Client, GatewayIntentBits } from 'discord.js'; |
| 46 | + import { CommandKit } from 'commandkit'; |
| 47 | + import { fileURLToPath } from 'url'; |
| 48 | + import path from 'path'; |
| 49 | + |
| 50 | + const client = new Client({ |
| 51 | + intents: [ |
| 52 | + GatewayIntentBits.Guilds, |
| 53 | + GatewayIntentBits.GuildMessages, |
| 54 | + GatewayIntentBits.MessageContent |
| 55 | + ], |
| 56 | + }); |
| 57 | + |
| 58 | + const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 59 | + |
| 60 | + new CommandKit({ |
| 61 | + client, |
| 62 | + commandsPath: path.join(__dirname, 'commands'), |
| 63 | + eventsPath: path.join(__dirname, 'events'), |
| 64 | + validationsPath: path.join(__dirname, 'validations'), |
| 65 | + devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'], |
| 66 | + devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'], |
| 67 | + devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'], |
| 68 | + skipBuiltInValidations: true, |
| 69 | + bulkRegister: true, |
| 70 | + }); |
| 71 | + |
| 72 | + client.login('YOUR_TOKEN_HERE'); |
| 73 | + ``` |
| 74 | + </TabItem> |
| 75 | + <TabItem value='ts' label='TypeScript'> |
| 76 | + ```ts title="src/index.ts" {2, 13-23} |
| 77 | + import { Client, GatewayIntentBits } from 'discord.js'; |
| 78 | + import { CommandKit } from 'commandkit'; |
| 79 | + import path from 'path'; |
| 80 | + |
| 81 | + const client = new Client({ |
| 82 | + intents: [ |
| 83 | + GatewayIntentBits.Guilds, |
| 84 | + GatewayIntentBits.GuildMessages, |
| 85 | + GatewayIntentBits.MessageContent |
| 86 | + ], |
| 87 | + }); |
| 88 | + |
| 89 | + new CommandKit({ |
| 90 | + client, |
| 91 | + commandsPath: path.join(__dirname, 'commands'), |
| 92 | + eventsPath: path.join(__dirname, 'events'), |
| 93 | + validationsPath: path.join(__dirname, 'validations'), |
| 94 | + devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'], |
| 95 | + devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'], |
| 96 | + devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'], |
| 97 | + skipBuiltInValidations: true, |
| 98 | + bulkRegister: true, |
| 99 | + }); |
| 100 | + |
| 101 | + client.login('YOUR_TOKEN_HERE'); |
| 102 | + ``` |
| 103 | + </TabItem> |
| 104 | +
|
| 105 | +</Tabs> |
| 106 | +
|
| 107 | +:::info |
| 108 | +Some Discord.js properties are only accessible using the correct intents. |
| 109 | +::: |
| 110 | +
|
| 111 | +## CommandKit options |
| 112 | +
|
| 113 | +### `client` |
| 114 | +
|
| 115 | +- Type: [`Client`](https://old.discordjs.dev/#/docs/discord.js/main/class/Client) |
| 116 | +
|
| 117 | +This is your Discord.js client object. This is required to register and handle application commands and events. |
| 118 | +
|
| 119 | +### `commandsPath` (optional) |
| 120 | +
|
| 121 | +- Type: `string` |
| 122 | +
|
| 123 | +This is the path to your commands directory. It's used to fetch, register, and listen for application commands. |
| 124 | +
|
| 125 | +### `eventsPath` (optional) |
| 126 | +
|
| 127 | +- Type: `string` |
| 128 | +
|
| 129 | +This is the path to your events directory. It's used to fetch and set event listeners based on the folder names inside of it. |
| 130 | +
|
| 131 | +### `validationsPath` (optional) |
| 132 | +
|
| 133 | +- Type: `string` |
| 134 | +
|
| 135 | +This is the path to your validations directory. It's used to fetch and call validation functions before running application commands. |
| 136 | +
|
| 137 | +### `devGuildIds` (optional) |
| 138 | +
|
| 139 | +- Type: `string[]` |
| 140 | +
|
| 141 | +This is a list of development server IDs. It's used to restrict commands marked with `devOnly` to specific servers. |
| 142 | +
|
| 143 | +If there is at least 1 guild ID provided, CommandKit will register any commands marked as `devOnly` inside the listed servers. |
| 144 | +
|
| 145 | +### `devUserIds` (optional) |
| 146 | +
|
| 147 | +- Type: `string[]` |
| 148 | +
|
| 149 | +This is a list of developer user IDs. It's used to restrict commands marked with `devOnly` to specific users. |
| 150 | +
|
| 151 | +Trying to execute a command when this is set to at-least 1 user ID will call a built-in validation function everytime to validate that the user running the command belongs to the provided `devUserIds` array. |
| 152 | +
|
| 153 | +### `devRoleIds` (optional) |
| 154 | +
|
| 155 | +- Type: `string[]` |
| 156 | +
|
| 157 | +This is a list of developer role IDs. It's used to restrict commands marked with `devOnly` to specific roles. |
| 158 | +
|
| 159 | +Trying to execute a command when this is set to at-least 1 role ID will call a built-in validation function everytime to validate that the user running the command has at least one of the provided roles. |
| 160 | +
|
| 161 | +### `skipBuiltInValidations` (optional) |
| 162 | +
|
| 163 | +- Type: `boolean` |
| 164 | +- Default: `false` |
| 165 | +
|
| 166 | +This is used to disable CommandKit's built-in validation functions. Setting this to `true` will ignore the default behaviour of validating who is running commands marked with `devOnly`. |
| 167 | +
|
| 168 | +### `bulkRegister` (optional) |
| 169 | +
|
| 170 | +- Type: `boolean` |
| 171 | +- Default: `false` |
| 172 | +
|
| 173 | +This is used to change the behaviour of how CommandKit loads application commands. By default it's one-by-one while comparing changes. Setting this option to `true` will load application commands all at once on every restart, and when [`reloadCommands()`](/docs/api-reference/classes/CommandKit#reloadcommands) is called. |
0 commit comments