Publish
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
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.
Your .env
file should look like this:
DISCORD_TOKEN=<YOUR_TOKEN>APPLICATION_ID=<YOUR_APPLICATION_ID>NODE_ENV=<production|development>
Usage
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
- This can be a function or a
Config
1type ValidMemberPermissions =2 | PermissionFlagBits // discord.js enum3 | PermissionFlagBits[] // array of discord.js enum4 | string // must be a stringified number (such as "8" for ADMINISTRATOR)5 | bigint6
7interface PublishConfig {8 guildIds?: string[];9 dmPermission?: boolean;10 defaultMemberPermissions: ValidMemberPermissions;11}12
13type ValidPublishOptions =14 | PublishConfig15 | (absPath: string, module: CommandModule) => PublishConfig
Prerequiring
Is there a service that is required at the top level of a command?
Create an ES6 script anywhere, such as:
1import { makeDependencies, single, Service } from "@sern/handler";2import { Client } from "discord.js";3
4await makeDependencies({5 build: (root) =>6 root.add({ "@sern/client": single(() => new Client(...options)) }),7});8
9await Service("@sern/client").login();
This will create a container for publishing.
Example
This example will publish a ping command to a specific guild: 889026545715400705
.
Script
sern commands publish -i ./scripts/prerequire.mjs
Command
1import { commandModule, Service, CommandType } from '@sern/handler'2
3const client = Service('@sern/client');4
5export const config = {6 guildIds: ["889026545715400705"]7}8
9export default commandModule( {10 type: CommandType.Slash11 description: `${client.user.username}'s ping`,12 execute: (ctx) => {13 ctx.reply('pong')14 }15})