Skip to content
sern

Publish

Terminal window
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:

.env
DISCORD_TOKEN=<YOUR_TOKEN>
APPLICATION_ID=<YOUR_APPLICATION_ID>
NODE_ENV=<production|development>

Usage

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

Config

1
type ValidMemberPermissions =
2
| PermissionFlagBits // discord.js enum
3
| PermissionFlagBits[] // array of discord.js enum
4
| string // must be a stringified number (such as "8" for ADMINISTRATOR)
5
| bigint
6
7
interface PublishConfig {
8
guildIds?: string[];
9
dmPermission?: boolean;
10
defaultMemberPermissions: ValidMemberPermissions;
11
}
12
13
type ValidPublishOptions =
14
| PublishConfig
15
| (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:

scripts/prerequire.mjs
1
import { makeDependencies, single, Service } from "@sern/handler";
2
import { Client } from "discord.js";
3
4
await makeDependencies({
5
build: (root) =>
6
root.add({ "@sern/client": single(() => new Client(...options)) }),
7
});
8
9
await 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

Terminal window
sern commands publish -i ./scripts/prerequire.mjs

Command

src/commands/ping.ts
1
import { commandModule, Service, CommandType } from '@sern/handler'
2
3
const client = Service('@sern/client');
4
5
export const config = {
6
guildIds: ["889026545715400705"]
7
}
8
9
export default commandModule( {
10
type: CommandType.Slash
11
description: `${client.user.username}'s ping`,
12
execute: (ctx) => {
13
ctx.reply('pong')
14
}
15
})