Configuring Seyfert
TypeScript Configuration
For Seyfert to work correctly, you need to update your tsconfig.json file and add emitDecoratorMetadata and experimentalDecorators to enable the use of decorators:
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
}
}{
"compilerOptions": {
"module": "CommonJS",
"target": "ESNext",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"preserveConstEnums": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true,
"noErrorTruncation": true,
"outDir": "./dist",
"rootDir": "./src",
"baseUrl": ".",
"stripInternal": true,
},
"exclude": ["node_modules"],
"include": ["src/**/*"]
}Recommended: type-aware linting
Now that TypeScript is set up, consider adding @slipher/eslint-plugin — a type-aware ESLint plugin that reads Seyfert's own types to catch common mistakes as you write. See the ESLint recipe to set it up.
Selecting the Bot Type
Seyfert supports two types of applications that interact with the Discord API: one based on the gateway (websocket) and another based on the HTTP interaction system.
Each type has a distinct purpose, and it is crucial to understand their differences to choose the one that best suits your needs. If you are unsure which bot type to choose, we recommend using the Gateway option.
- The Gateway client handles all events emitted by Discord, such as
messageCreate,interactionCreate,guildCreate,ready, among others. - The available events depend on the intents configured in the client.
- Unlike the gateway, the HTTP client does not handle events.
- Its functionality is limited to receiving interactions (commands and components) through HTTP requests sent from Discord.
Configuration
Once you have modified the tsconfig.json to support decorators, there are a few more steps before you can run your application. Seyfert is set up to automatically load your commands, events, components, and language.
For this, you need to create a file called seyfert.config.mjs in the root folder of your project and add the configuration according to the bot type you selected:
import { config } from "seyfert";
export default config.bot({
token: process.env.BOT_TOKEN ?? "",
locations: {
base: "dist", // replace with "src" if using bun
commands: "commands"
},
intents: ["Guilds"],
// This configuration is optional, in case you want to receive interactions via HTTP
// This allows you to use both the gateway and the HTTP webhook
publicKey: "...", // replace with your public key
port: 4444, // replace with your application's port
});import { config } from "seyfert";
const {
BOT_TOKEN, BOT_APP_ID, BOT_PUBLIC_KEY
} = process.env;
export default config.http({
token: BOT_TOKEN,
locations: {
base: "dist", // replace with "src" if using bun
commands: "commands"
},
applicationId: BOT_APP_ID,
port: 3000, // default is 8080
publicKey: BOT_PUBLIC_KEY,
});This is not all, you also need to create a main file called index.ts inside the src folder (specified as base in the configuration) and start using it.
import { Client } from "seyfert";
const client = new Client();
// This will start the connection with the Discord gateway and load commands, events, components, and language (i18n)
client.start();import { HttpClient } from "seyfert";
import { UwsAdapter } from "@slipher/uws-adapter";
// import { GenericAdapter } from "@slipher/generic-adapter";
const client = new HttpClient();
const adapter = new UwsAdapter(client); // You can also pass a `Client` or `WorkerClient`.
// This will start listening at `https://yourweb.xyz/interactions` and load commands, components, and language (i18n)
client.start();
adapter.start();If you're using Cloudflare Workers, we recommend following the guide on their official page.
In addition to the above, you need to configure the appropriate types based on the client you are using:
import type { ParseClient, Client, HttpClient, WorkerClient } from 'seyfert';
declare module 'seyfert' {
interface SeyfertRegistry {
client: ParseClient<Client<true>>; // Gateway
// client: ParseClient<HttpClient>; // HTTP
// client: ParseClient<WorkerClient<true>>; // Worker
}
}For more information on how to declare types and what you can do with them, visit extending declare module.
Once these steps are completed, your project structure should look like this: