Getting Started

Creating Your First Command

The main input for any Discord bot is its commands. In Seyfert, you can easily create and manage commands. Seyfert will handle loading and executing all the commands you create within the commands folder (as specified in the configuration).

To get started, let's create the following file and use the ping command as an example.
All commands must use the @Declare decorator for their information and a class that extends Command:

src/commands/ping.ts
import { , , type  } from 'seyfert';
 
@({
  : 'ping',
  : 'Show latency with Discord'
})
export default class  extends  {
  async (: ) {
    // Average latency between existing connections
    const  = ...;
 
    await .({
      : `The latency is \`${}\``
    });
  }
}

Before you can execute new commands, you need to register them with Discord. You can do this using the following code:

src/index.ts
import {  } from 'seyfert';
 
const  = new ();
 
.()
  .(() => .({ : './commands.json' }));

When the bot starts, the commands will be uploaded to Discord, and a ./commands.json file (cachePath) will be created to store them. This helps detect changes and prevents re-uploading them every time.

With this, you can run your bot and test the /ping command on Discord. You should see your bot's latency!

Using Options

Simple enough, right? However, commands don't always respond the same way every time you execute them. Sometimes, we need to interpret what the user actually needs. This is where options come into play.

Let's configure this command so its response is invisible to other users (an ephemeral message).
To achieve this, we'll use the @Options decorator and create a hide option of type boolean:

src/commands/ping.ts
import {
  ,
  ,
  ,
  ,
  type 
} from 'seyfert';
import {  } from 'seyfert/lib/types';
 
const  = {
  : ({
    : "Hide the command's response",
  }),
};
 
@({
  : 'ping',
  : 'Show latency with Discord'
})
@()
export default class  extends  {
 
  async (: <typeof >) {
    const  = .. ? . : ;
    
    // Average latency between existing connections
    const  = ...;
 
    await .({
      : `The latency is \`${}\``,
      ,
    });
  }
}

The CommandContext is extended with a generic to infer the type of options and provide access to them.

More information about command options can be found here.

You can create additional folders inside the commands folder to keep your files organized.

Your project structure should look like this:

src
commands
index.ts
package.json
seyfert.config.mjs
tsconfig.json

On this page