Updating seyfert config
Before starting this chapter we shall update seyfert.config.js
in order to tell seyfert where our commands file will be.
const { config } = require ( ' seyfert ' );
module . exports = config . bot ({
token: process . env . BOT_TOKEN ?? "" ,
commands: " commands " // - src/commands will be our commands directory
Declaring commands
Each command file needs to export by default the command class so seyfert is able to load it.
For this example we’ll setup ping
command, let’s start by declaring the ping command class as shown below.
import { Declare, Command, type CommandContext } from ' seyfert ' ;
description: ' Show the ping with discord '
export default class PingCommand extends Command {
async run ( ctx : CommandContext ) {
// average latency between shards
const ping = ctx . client . gateway . latency ;
content: ` The ping is \` ${ ping } \` `
import { Declare, Command, type CommandContext } from ' seyfert ' ;
import { snowflakeToTimestamp } from ' seyfert/lib/common ' ;
description: ' Show the ping with discord ' ,
export default class PingCommand extends Command {
async run ( ctx : CommandContext ) {
// latency between discord creating the interaction and it being computed
Date . now () - Number ( snowflakeToTimestamp (ctx . interaction . id ))
content: ` The ping is \` ${ ping } \` ` ,
To test whether your command works, you must publish it on Discord before making minor changes to your main file:
import { Client, ParseClient } from " seyfert " ;
const client = new Client ();
client . start () . then ( () => client . uploadCommands ());
// here goes the declare module made in the previous step
Pretty simple, isn’t it? But sometimes commands are not just about receiving a request and responding it, you also have to think about what the user wants, that’s where the options
come in, let’s add an option to hide the response.
Using options
import { MessageFlags } from ' seyfert/lib/types ' ;
hide: createBooleanOption ( {
description: " Hide command output " ,
description: ' Show the ping with discord '
export default class PingCommand extends Command {
async run ( ctx : CommandContext < typeof options> ) {
const flags = ctx . options . hide ? MessageFlags . Ephemeral : undefined ;
// average latency between shards
// in http change this for the example above
const ping = ctx . client . gateway . latency ;
content: ` The ping is \` ${ ping } \` ` ,
Below is how the file tree should look like after adding the command.
Directory src
Directory commands
index.ts package.json seyfert.config.js .env tsconfig.json