mirror of
https://github.com/sern-handler/website
synced 2026-06-06 01:16:47 +00:00
fix: fix CLI on sidebar
This commit is contained in:
@@ -60,7 +60,7 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
label: "CLI",
|
||||
autogenerate: { directory: "cli" },
|
||||
autogenerate: { directory: "v3/cli" },
|
||||
},
|
||||
{
|
||||
label: "Guide",
|
||||
@@ -82,7 +82,7 @@ export default defineConfig({
|
||||
items: [
|
||||
{
|
||||
label: "CLI",
|
||||
autogenerate: { directory: "cli" },
|
||||
autogenerate: { directory: "v4/cli" },
|
||||
},
|
||||
{
|
||||
label: "Reference",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { defineCollection, getCollection } from "astro:content";
|
||||
import { defineCollection } from "astro:content";
|
||||
import { docsSchema } from "@astrojs/starlight/schema";
|
||||
import { blogSchema } from "starlight-blog/schema";
|
||||
|
||||
|
||||
@@ -41,4 +41,4 @@ To install extra utilities into your project, run:
|
||||
sern extra
|
||||
```
|
||||
|
||||
We have a more in depth [guide](/cli/about) on the CLI if you're interested in learning more.
|
||||
We have a more in depth [guide](/v3/cli/about) on the CLI if you're interested in learning more.
|
||||
|
||||
35
src/content/docs/v4/cli/about.mdx
Normal file
35
src/content/docs/v4/cli/about.mdx
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
title: About the CLI
|
||||
description: The CLI is your pocketknife for discord bot development. It'll have all features necessary for developing and shipping to production.
|
||||
---
|
||||
|
||||
Publish commands to the API, install plugins, and use other tools provided by our cli.
|
||||
|
||||
The CLI is your pocketknife for discord bot development. It'll have all features necessary for developing and shipping to production.
|
||||
|
||||
```ansi
|
||||
Usage: sern [options] [command]
|
||||
|
||||
|
||||
___ ___ _ __ _ __
|
||||
/ __|/ _ \ '__| '_ \
|
||||
\__ \ __/ | | | | |
|
||||
|___/\___|_| |_| |_|
|
||||
|
||||
Welcome!
|
||||
|
||||
If you're new to [36msern[0m, run [35mnpm create @sern/bot[0m for an interactive setup to your new bot project!
|
||||
|
||||
[33mIf you have any ideas, suggestions, bug reports, kindly join our support server: https://sern.dev/discord[0m
|
||||
|
||||
Options:
|
||||
-v, --version output the version number
|
||||
-h, --help display help for command
|
||||
|
||||
Commands:
|
||||
init [options] Quickest way to scaffold a new project [93m[DEPRECATED][0m
|
||||
plugins [options] Install plugins from https://github.com/sern-handler/awesome-plugins
|
||||
extra Easy way to add extra things in your sern project
|
||||
commands Defacto way to manage your slash commands
|
||||
help [command] display help for command
|
||||
```
|
||||
208
src/content/docs/v4/cli/build.mdx
Normal file
208
src/content/docs/v4/cli/build.mdx
Normal file
@@ -0,0 +1,208 @@
|
||||
---
|
||||
title: Build
|
||||
description: Build your bot using the sern CLI tool
|
||||
---
|
||||
|
||||
```sh
|
||||
Usage: sern build [options]
|
||||
|
||||
Build your bot
|
||||
|
||||
Options:
|
||||
-f --format [fmt] The module system of your application. `cjs` or `esm` (default: "esm")
|
||||
-m --mode [mode] the mode for sern to build in. `production` or `development` (default: "development")
|
||||
-W --suppress-warnings suppress experimental warning
|
||||
-p --project [filePath] build with this sern.build file
|
||||
-h, --help display help for command
|
||||
```
|
||||
|
||||
## Guiding Principles
|
||||
|
||||
When designing the `sern build` command, our aim was to make building bot applications as simple as possible for the majority of developers. The setup process has been streamlined, and most of the configuration details have been handled for you.
|
||||
|
||||
Here are some key points to keep in mind:
|
||||
|
||||
import { Steps } from '@astrojs/starlight/components';
|
||||
|
||||
<Steps>
|
||||
1. **Minimal Configuration**: In the vast majority (99%) of use cases, developers do not need to configure the bot application building process. We believe that simplicity is key, so only a few decisions need to be made on the developer's end.
|
||||
|
||||
2. **Optimal Defaults**: We've chosen sensible defaults. This means you can get started without getting bogged down by complex, unneeded configurations.
|
||||
|
||||
3. **Finetuned for production bots**: Our CLI leverages an opinionated build solution powered by esbuild. This ensures that bots are built without issues and can be shipped easily.
|
||||
</Steps>
|
||||
|
||||
## Experimental Features
|
||||
|
||||
Both the `sern build` and `sern publish` commands are marked as experimental. While they might not be completely stable, they are designed to work for the majority of users. We appreciate any feedback in helping us make these features even better.
|
||||
|
||||
## Features
|
||||
|
||||
The `sern build` command comes equipped with a range of features designed to enhance your development process. Here's a glimpse of what it offers:
|
||||
|
||||
- **esbuild Integration**: our CLI takes inspiration from the efficiency of SvelteKit, ensuring your bot application is built effectively and with type safety. Leverage the [esbuild plugin ecosystem](https://github.com/esbuild/community-plugins).
|
||||
|
||||
- **Zero Configuration**: Building your bot application without additional configuration. The CLI handles most of the setup for you.
|
||||
|
||||
- **Experimental Image Support**: We've introduced experimental support for top-level imports of PNG and JPG files, making it easier to include images in your bot application.
|
||||
|
||||
- **Compile Time Constants**: Customize your build with constants such as `__DEV__`, `__PROD__`, allowing you to tailor your application to different production stages.
|
||||
|
||||
- **Development and Production Modes**: The CLI supports both development and production modes, enabling you to tailor your bot application for different stages of development.
|
||||
|
||||
- **Type-safe `process.env`**: The CLI generates a type-safe `process.env`, reducing potential errors.
|
||||
|
||||
## Implicits
|
||||
|
||||
- Command line arguments take precendence over `sern.build` configuration file
|
||||
- Default build format is ESM
|
||||
- `defineVersion = true`
|
||||
- `__DEV__` AND `__PROD__` constants are configured.
|
||||
- Only a [few tsconfig options](https://esbuild.github.io/content-types/#tsconfig-json) are respected.
|
||||
|
||||
### `sern.build.js`
|
||||
|
||||
The `sern.build.js` file is for any extra configuration you may need, such as adding esbuild plugins.
|
||||
|
||||
The CLI was intentionally made to be installed globally, and we can't provide typings at a project level. If you need typings, here they are:
|
||||
|
||||
```ts
|
||||
type BuildOptions = {
|
||||
/**
|
||||
* Define __VERSION__
|
||||
* This option is a quick switch to defining the __VERSION__ constant which will be a string of the version provided in
|
||||
* cwd's package.json
|
||||
*/
|
||||
defineVersion?: boolean;
|
||||
/**
|
||||
* default = esm
|
||||
*/
|
||||
format?: "cjs" | "esm";
|
||||
/**
|
||||
* extra esbuild plugins to build with sern.
|
||||
*/
|
||||
esbuildPlugins?: esbuild.Plugin[];
|
||||
/**
|
||||
* https://esbuild.github.io/api/#drop-labels
|
||||
**/
|
||||
dropLabels?: string[];
|
||||
/**
|
||||
* https://esbuild.github.io/api/#define
|
||||
**/
|
||||
define?: Record<string, string>;
|
||||
/**
|
||||
* Path to tsconfig
|
||||
**/
|
||||
tsconfig?: string;
|
||||
/**
|
||||
* default = 'development'
|
||||
*/
|
||||
mode: "production" | "development";
|
||||
/**
|
||||
* will search for env file. If none exists,
|
||||
* default to .env.
|
||||
*/
|
||||
env?: string;
|
||||
};
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
sern build
|
||||
```
|
||||
|
||||
(that was easy)
|
||||
|
||||
## Adapting Older Projects
|
||||
|
||||
Change your `tsconfig.json` to extend our generated one, `./.sern/tsconfig.json`.
|
||||
|
||||
```json {2}
|
||||
{
|
||||
"extends": "./.sern/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
// all of your old fields
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## In Depth
|
||||
|
||||
We use the `define` and `drop labels` API in C style macros to have easy development stage differences. [Here](https://esbuild.github.io/api/#drop-labels) is the esbuild full API documentation
|
||||
|
||||
### Drop Labels
|
||||
|
||||
```sh
|
||||
# mode is set to production
|
||||
sern build
|
||||
```
|
||||
|
||||
import { Tabs, TabItem } from '@astrojs/starlight/components';
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="input" label="Input">
|
||||
```ts
|
||||
__DEV__: console.log("This is for production only");
|
||||
__PROD__: console.log("This is for either mode");
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="sh" label="Running build for production">
|
||||
```sh
|
||||
# mode is set to production
|
||||
sern build
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="output" label="Output">
|
||||
```ts
|
||||
__PROD__ console.log('This is for either mode')
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
### Constants
|
||||
|
||||
sern builds with three default constants. `__DEV__`, `__PROD__`, `__VERSION__`, where `__VERSION__` is the version in your build options, or `package.json` if unspecified.
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="input" label="Preprocess">
|
||||
```sh
|
||||
sern build
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem value="sh" label="Constants available and typesafe!">
|
||||
```ts
|
||||
if (__PROD__) {
|
||||
console.log("Bot version: " + __VERSION__);
|
||||
}
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
Full esbuild documentation [here](https://esbuild.github.io/api/#define). Add more to the `define` field in build options (only availible with a `sern.build` file at the moment)
|
||||
|
||||
### `process.env`
|
||||
|
||||
We generate your process.env with `dotenv` and generate typings for process.env. Less hassle!
|
||||
|
||||
<Tabs>
|
||||
<TabItem value="input" label=".env">
|
||||
```sh frame="none"
|
||||
DISCORD_TOKEN=<your token>
|
||||
```
|
||||
|
||||
```ts
|
||||
process.env.DISCORD_TOKEN; // string | undefined (not typesafe :()
|
||||
```
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="sh" label="sern build">
|
||||
```sh
|
||||
sern build
|
||||
```
|
||||
|
||||
```ts
|
||||
process.env.DISCORD_TOKEN; // string (typesafe :))
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
40
src/content/docs/v4/cli/clear.mdx
Normal file
40
src/content/docs/v4/cli/clear.mdx
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
title: Clear
|
||||
description: Clear and reset your commands, both globally and per guild
|
||||
---
|
||||
|
||||
```sh
|
||||
Usage: sern commands clear [options]
|
||||
|
||||
Clear and reset commands-data-remote.json and the api
|
||||
|
||||
Options:
|
||||
-y, --yes Say yes to all prompts
|
||||
-e, --env [path] Supply a path to a .env
|
||||
-h, --help display help for command
|
||||
```
|
||||
|
||||
## Introduction
|
||||
|
||||
The clear command is a utility that resets all of your commands. It's useful if you accidentally publish the wrong command, such as publishing a guild command globally.
|
||||
|
||||
The clear command works by sending an empty array via the [`PUT`](https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands) route to the Discord API, for each guild and globally.
|
||||
|
||||
To use this command, ensure you have a proper `.env` file in your root directory:
|
||||
|
||||
```sh title=".env"
|
||||
DISCORD_TOKEN=<YOUR_TOKEN>
|
||||
APPLICATION_ID=<YOUR_APPLICATION_ID>
|
||||
NODE_ENV=<development|production>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
sern commands clear
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- The clear command will prompt you to confirm the action. You can bypass this by using the `-y` flag.
|
||||
- The clear command will automatically read a `.env` file in the working directory. If you need to override this, you can use the `-e` flag to supply a path to a different `.env` file.
|
||||
27
src/content/docs/v4/cli/extra.mdx
Normal file
27
src/content/docs/v4/cli/extra.mdx
Normal file
@@ -0,0 +1,27 @@
|
||||
---
|
||||
title: Extra
|
||||
description: Add extra features to your sern project
|
||||
---
|
||||
|
||||
```sh
|
||||
Usage: sern extra [options]
|
||||
|
||||
Easy way to add extra things in your sern project
|
||||
|
||||
Options:
|
||||
-h, --help display help for command
|
||||
```
|
||||
|
||||
## Introduction
|
||||
|
||||
This command is pretty straightfoward. Install utilities into your application, assuming you have a `sern.config.json`.
|
||||
|
||||
You can use this command to install things such as a `Dockerfile`
|
||||
|
||||
## Usage
|
||||
|
||||
```ansi frame
|
||||
[33m❯[0m sern extra
|
||||
[90m# Choose which extra feature from the prompt, such as this:[0m
|
||||
[33m✔[0m What extra feature do you want to add? [90m›[0m Dockerfile (TypeScript)
|
||||
```
|
||||
131
src/content/docs/v4/cli/publish.mdx
Normal file
131
src/content/docs/v4/cli/publish.mdx
Normal file
@@ -0,0 +1,131 @@
|
||||
---
|
||||
title: Publish
|
||||
description: Publish your commands to Discord
|
||||
---
|
||||
|
||||
```sh
|
||||
Usage: sern commands publish [options] [path]
|
||||
|
||||
New way to manage your slash commands
|
||||
|
||||
Arguments:
|
||||
path path with respect to current working directory that will locate all published files
|
||||
|
||||
Options:
|
||||
-i, --import [scriptPath...] Prerequire a script to load into publisher
|
||||
-t, --token [token]
|
||||
--appId [applicationId]
|
||||
-h, --help display help for command
|
||||
```
|
||||
|
||||
## Introduction
|
||||
|
||||
The publish command is a way to publish slash commands to Discord. It uses the [`PUT`](https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands) route to overwrite existing commands.
|
||||
|
||||
Wherever your commands directory is located, publish will override the existing application commands on Discord. Existing commands do not count towards the command limit creation daily.
|
||||
|
||||
The publish command automatically reads your `.env` file in the working directory. If you do not have a `.env` file, you can pass in the `--token` and `--appId` flags.
|
||||
|
||||
:::caution
|
||||
CLI arguments, if specified, take precedence over `.env` file.
|
||||
:::
|
||||
|
||||
Your `.env` file should look like this:
|
||||
|
||||
```sh title=".env"
|
||||
DISCORD_TOKEN=<YOUR_TOKEN>
|
||||
APPLICATION_ID=<YOUR_APPLICATION_ID>
|
||||
NODE_ENV=<production|development>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
:::caution
|
||||
CommonJS and JavaScript users need to compile first, then run `sern publish` on the `dist` output
|
||||
:::
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- Automatically syncs API with your command base
|
||||
- Generates a JSON file of output (`.sern/command-data-remote.json`)
|
||||
- Supports publishing direct ESM TypeScript files
|
||||
- Prerequire scripts are supported
|
||||
- Supports a configuration that is the same as the original publish plugin
|
||||
- Each command file can have an extra config that follows `ValidPublishOptions`
|
||||
- This can be a function or a `PublishConfig` object
|
||||
|
||||
## Config
|
||||
|
||||
```ts {13-15}
|
||||
type ValidMemberPermissions =
|
||||
| PermissionFlagBits // discord.js enum
|
||||
| PermissionFlagBits[] // array of discord.js enum
|
||||
| string // must be a stringified number (such as "8" for ADMINISTRATOR)
|
||||
| bigint
|
||||
|
||||
interface PublishConfig {
|
||||
guildIds?: string[];
|
||||
dmPermission?: boolean;
|
||||
defaultMemberPermissions: ValidMemberPermissions;
|
||||
}
|
||||
|
||||
type ValidPublishOptions =
|
||||
| PublishConfig
|
||||
| (absPath: string, module: CommandModule) => PublishConfig
|
||||
```
|
||||
|
||||
## Prerequiring
|
||||
|
||||
Is there a [service](/v3/guide/walkthrough/services) that is required at the top level of a command?
|
||||
|
||||
Create an ES6 script anywhere, such as:
|
||||
|
||||
```ts title="scripts/prerequire.mjs"
|
||||
import { makeDependencies, single, Service } from "@sern/handler";
|
||||
import { Client } from "discord.js";
|
||||
|
||||
await makeDependencies({
|
||||
build: (root) =>
|
||||
root.add({ "@sern/client": single(() => new Client(...options)) }),
|
||||
});
|
||||
|
||||
await Service("@sern/client").login();
|
||||
```
|
||||
|
||||
This will create a container for publishing.
|
||||
|
||||
:::danger
|
||||
As of 0.6.0, the `client` is required, or this will crash.
|
||||
:::
|
||||
|
||||
## Example
|
||||
|
||||
This example will publish a ping command to a specific guild: `889026545715400705`.
|
||||
|
||||
### Script
|
||||
|
||||
```sh
|
||||
sern commands publish -i ./scripts/prerequire.mjs
|
||||
```
|
||||
|
||||
### Command
|
||||
|
||||
```ts title=src/commands/ping.ts {5-7}
|
||||
import { commandModule, Service, CommandType } from '@sern/handler'
|
||||
|
||||
const client = Service('@sern/client');
|
||||
|
||||
export const config = {
|
||||
guildIds: ["889026545715400705"]
|
||||
}
|
||||
|
||||
export default commandModule( {
|
||||
type: CommandType.Slash
|
||||
description: `${client.user.username}'s ping`,
|
||||
execute: (ctx) => {
|
||||
ctx.reply('pong')
|
||||
}
|
||||
})
|
||||
```
|
||||
Reference in New Issue
Block a user