Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ jobs:
name: 🔍 Lint
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v2
with:
version: 8

- name: 📚 Checkout
uses: actions/checkout@v3

Expand All @@ -20,7 +24,7 @@ jobs:
registry-url: https://registry.npmjs.org

- name: 🍳 Prepare
run: npm install
run: pnpm install

- name: ✨ Lint
run: npm run lint
run: pnpm lint
10 changes: 6 additions & 4 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
name: 🚀 Publish
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v2
with:
version: 8

- name: 📚 Checkout
uses: actions/checkout@v3

Expand All @@ -19,11 +23,9 @@ jobs:
registry-url: https://registry.npmjs.org

- name: 🍳 Prepare
run: |
npm install
npm run build
run: pnpm install

- name: 🚚 Publish
run: npm publish
run: pnpm run publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules
/dist
node_modules
dist
.DS_Store
.vscode
.vscode
.turbo
18 changes: 15 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/node_modules
/dist
node_modules

dist
.astro

.DS_Store
.vscode

README.md
yarn.lock
pnpm-lock.yaml

npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

.env
.env.production
21 changes: 21 additions & 0 deletions apps/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# build output
dist/

# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
3 changes: 3 additions & 0 deletions apps/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CommandKit Docs

The official docs for CommandKit
47 changes: 47 additions & 0 deletions apps/docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';

// https://astro.build/config
export default defineConfig({
site: 'https://commandkit.underctrl.io',
integrations: [
starlight({
title: '',
favicon: '/favicon.png',
logo: {
dark: './src/assets/nav_logo.png',
light: './src/assets/nav_logo_light.png',
},
editLink: {
baseUrl: 'https://github.com/underctrl-io/commandkit-docs/edit/master/',
},
customCss: ['./src/styles/landing.css', './src/styles/custom.css'],
lastUpdated: true,
social: {
github: 'https://github.com/underctrl-io/commandkit',
discord: 'https://discord.underctrl.io',
youtube: 'https://youtube.com/@UnderCtrl',
},
sidebar: [
{ label: 'Overview', link: '/overview' },
{
label: 'Guides',
items: [
{ label: 'Installation', link: '/guides/installation' },
{ label: 'CommandKit Setup', link: '/guides/commandkit-setup' },
{ label: 'Commands Setup', link: '/guides/command-file-setup' },
{ label: 'Events Setup', link: '/guides/event-file-setup' },
{ label: 'Validations Setup', link: '/guides/validation-file-setup' },
{
label: 'Migrate from DJS-Commander',
link: '/guides/migrating-from-djs-commander',
},
],
},
],
}),
],

// Process images with sharp: https://docs.astro.build/en/guides/assets/#using-sharp
image: { service: { entrypoint: 'astro/assets/services/sharp' } },
});
19 changes: 19 additions & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "docs",
"type": "module",
"version": "0.0.10",
"private": true,
"license": "MIT",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/starlight": "^0.7.2",
"astro": "^2.10.8",
"sharp": "^0.32.1"
}
}
Binary file added apps/docs/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/docs/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/docs/src/assets/nav_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added apps/docs/src/assets/nav_logo_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions apps/docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineCollection } from 'astro:content';
import { docsSchema } from '@astrojs/starlight/schema';

export const collections = {
docs: defineCollection({ schema: docsSchema() }),
};
81 changes: 81 additions & 0 deletions apps/docs/src/content/docs/guides/command-file-setup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: Commands Setup
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

CommandKit supports both slash commands and context menu commands. And since both have very similar triggers (interactions) and command structures, they are both stored and handled from within the commands directory for convenience.

This is a simple overview of how to set up a simple "ping" slash command that simply replies with "Pong!".

<Tabs>
<TabItem label="CommonJS">
```js
// commands/misc/ping.js
module.exports = {
data: {
name: 'ping',
description: 'Pong!',
},

run: ({ interaction, client }) => {
interaction.reply(`:ping_pong: Pong! ${client.ws.ping}ms`);
},

options: {
devOnly: true,
guildOnly: true,
userPermissions: ['Administrator', 'AddReactions'],
botPermissions: ['Administrator', 'AddReactions'],
deleted: false,
},
};
```
</TabItem>

<TabItem label="ESM">
```js
// commands/misc/ping.js
export const data = {
name: 'ping',
description: 'Pong!',
},

export function run({ interaction, client }) {
interaction.reply(`:ping_pong: Pong! ${client.ws.ping}ms`);
},

export const options = {
devOnly: true,
guildOnly: true,
userPermissions: ['Administrator', 'AddReactions'],
botPermissions: ['Administrator', 'AddReactions'],
deleted: false,
},
```
</TabItem>

</Tabs>

### Required properties

Every command file must export an object with the following properties:

- `data` - An object containing the command's structural information. This what will be used to register and handle your commands.

This can also be set to the [`SlashCommandBuilder`](https://discord.js.org/docs/packages/builders/0.16.0/SlashCommandBuilder:Class) class, or the [`ContextMenuCommandBuilder`](https://discord.js.org/docs/packages/builders/0.16.0/ContextMenuCommandBuilder:Class) class if that's what you're comfortable with.

- `run` - A function that will be called when your command is executed. This function also has an object passed to it as an argument with the following properties:
- `interaction` - The interaction object that triggered the command. This can either be a chat input interaction or a context menu interaction.
- `client` - The Discord client object.

### Optional properties

There is an additional optional property that can also be exported within the object above:

- `options` - An object which tells the command how to behave during registration and handling. This object has the following optional properties:
- `devOnly` - A boolean that determines whether the command should only be registered in development guilds and be executed by the bot developers. These properties are setup as `devGuildIds`, `devUserIds`, and `devRoleIds` when [instantiating `CommandKit`](/guides/commandkit-setup/).
- `guildOnly` - A boolean that determines whether the command should only be handled in guilds.
- `userPermissions` - An array of permission strings/bits that determines whether the user has the required permissions to execute the command. This is checked against the user's permissions in the guild where the command was executed (if any).
- `botPermissions` - An array of permission strings/bits that determines whether the bot has the required permissions to execute the command. This is checked against the bot's permissions in the guild where the command was executed (if any).
- `deleted` - A boolean that determines whether the command should be deleted on the next app restart.
100 changes: 100 additions & 0 deletions apps/docs/src/content/docs/guides/commandkit-setup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
title: CommandKit setup
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

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 point file (e.g. `index.js`) where you have access to your Discord client object.

<Tabs>
<TabItem label="CommonJS">
```js
// index.js
const { Client, GatewayIntentBits } = require('discord.js');
const { CommandKit } = require('commandkit');
const path = require('path');

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
});

new CommandKit({
client,
commandsPath: path.join(__dirname, 'commands'),
eventsPath: path.join(__dirname, 'events'),
validationsPath: path.join(__dirname, 'validations'),
devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'],
devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'],
devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'],
skipBuiltInValidations: true,
});

client.login('YOUR_TOKEN_HERE');
```
</TabItem>

<TabItem label="ESM">
```js
// index.js
import { Client, GatewayIntentBits } from 'discord.js';
import { CommandKit } from 'commandkit';
import { fileURLToPath } from 'url';
import path from 'path';

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
});

const __dirname = path.dirname(fileURLToPath(import.meta.url));

new CommandKit({
client,
commandsPath: path.join(__dirname, 'commands'),
eventsPath: path.join(__dirname, 'events'),
validationsPath: path.join(__dirname, 'validations'),
devGuildIds: ['DEV_SERVER_ID_1', 'DEV_SERVER_ID_2'],
devUserIds: ['DEV_USER_ID_1', 'DEV_USER_ID_2'],
devRoleIds: ['DEV_ROLE_ID_1', 'DEV_ROLE_ID_2'],
skipBuiltInValidations: true,
});

client.login('YOUR_TOKEN_HERE');
```
</TabItem>

</Tabs>

### Client intents

:::note
Some Discord.js properties are only accessible using the correct intents.
:::

Intents limit the data your bot receives from the Discord API. In the example above, the most important intents are already set (Guilds, Guild Messages, and Message Content). If you need access to more data such as Guild Members, you can add this into the `intents` array within the `Client`
constructor, a [list of intents can be found here](https://discord-api-types.dev/api/discord-api-types-v10/enum/GatewayIntentBits).

### Required properties

- `client` - Your Discord.js client object.

### Optional properties

- `commandsPath` - Path to the commands folder.
- `eventsPath` - Path to your events folder.
- `validationsPath` - Path to the validations folder. This will only work if `commandsPath` was provided.
- `devGuildIds` - Array of development server IDs. Used to register and run developer only commands in specific servers.
- `devUserIds` - Array of developer user IDs. Used to ensure developer only commands can only be ran by these users.
- `devRoleIds` - Array of developer role IDs. Used to ensure developer only commands can only be ran by users with these roles.
- `skipBuiltInValidations` - A property that disables CommandKit's built-in validations.

:::note
It's highly recommended to use the "path" library to define your paths to avoid any file import issues.
:::
Loading