Skip to content
sern

Publisher

Publish application commands as a service!

Usage

Initializing the Publisher

1
import { makeDependencies } from '@sern/handler';
2
import { Publisher } from '@sern/publisher';
3
4
await makeDependencies(({ add }) => {
5
add('publisher', (deps) => new Publisher(deps['@sern/modules'], deps['@sern/emitter'], deps['@sern/logger']));
6
});

Implicits

  • Requires process.env to be populated
  • A common provider of this is dotenv
.env
DISCORD_TOKEN=<YOUR_TOKEN>
NODE_ENV=<production|development>
  • Calls the discord API with the PUT route. Wherever your commands directory is located, publish will override the existing application commands at Discord.

Features

  • Automatically syncs api with your command base
  • generates JSON file of output (.sern/command-data-remote.json)
  • supports a configuration that is the same as the original publish plugin.

Each command file can have an extra plugin publishConfig that follows ValidPublishOptions:

Config

1
enum IntegrationContextType {
2
GUILD = 0,
3
BOT_DM = 1,
4
PRIVATE_CHANNEL = 2
5
}
6
7
type Contexts = IntegrationContextType | 0 | 1 | 2;
8
9
type ValidMemberPermissions =
10
| typeof PermissionFlagsBits //discord.js enum
11
| Array<typeof PermissionFlagsBits>
12
| bigint
13
14
interface PublishConfig {
15
guildIds?: Array<`${number}`>;
16
defaultMemberPermissions?: ValidMemberPermissions;
17
integrationTypes?: Array<'Guild'|'User'>;
18
contexts?: Array<Contexts>;
19
}
20
type ValidPublishOptions =
21
| PublishConfig
22
| (absPath: string, module: CommandModule) => PublishConfig

Example: command published with integrationTypes

src/commands/ping.ts
1
import { commandModule, CommandType } from '@sern/handler'
2
import { publishConfig } from '@sern/publisher'
3
4
export default commandModule( {
5
type: CommandType.Slash,
6
plugins: [
7
publishConfig({
8
integrationTypes: ['User'],
9
contexts: [1,2]
10
})
11
],
12
description: `hello worl`,
13
execute: (ctx) => {
14
ctx.reply('pong')
15
}
16
})

Example: command published in guild

src/commands/ping.ts
1
import { commandModule, CommandType } from '@sern/handler'
2
import { publishConfig } from '@sern/publisher'
3
4
export default commandModule( {
5
type: CommandType.Slash,
6
plugins: [
7
publishConfig({
8
guildIds: ["889026545715400705"]
9
})
10
],
11
description: `hello world`,
12
execute: (ctx) => {
13
ctx.reply('pong')
14
}
15
})

Explanation of each property in the plugin

  • guildIds: Commands will be published to guilds specified.

    • Can have more than one guild id to publish certain commands in
    • These commands cannot be used in dms.
  • defaultMemberPermissions: Only members with specified permissions can view the command

    • If you specify more than one, all perms are required!
  • integrationTypes: able to specify guild install or user install commands

    • ’Guild’: Command is only able to be used in guilds
    • ’User’: Command can be installed to a users profile to be used everywhere (with limitations)
      • Guilds with less than 200 members, developer can specify if the command should be invisible to others (ephemeral)
      • Guild with >= 200 members, commands will be forced to be invisible by the Discord API.
  • contexts: specify where the user installed commands can be used.

    • 0: Only available to be used by the user in GUILDS.
    • 1: Only available in Bot dms.
    • 2: Any private channel, such as a group dm outside of bots dms.
    • Also able to use IntegrationContextType enum from @sern/publisher if you don’t want to use numbers.