Setup Seyfert Project
Typescript settings
To make Seyfert work as intended you must update your tsconfig.json
file and add emitDecoratorMetadata
and experimentalDecorators
to be able to use decorators:
1{2 "compilerOptions": {3
4 "emitDecoratorMetadata": true,5 "experimentalDecorators": true,6 }7}
1{2 "compilerOptions": {3 "module": "CommonJS",4 "target": "ESNext",5 "moduleResolution": "node",6 "strict": true,7 "esModuleInterop": true,8 "experimentalDecorators": true,9 "emitDecoratorMetadata": true,10 "preserveConstEnums": true,11 "noImplicitAny": true,12 "strictNullChecks": true,13 "strictFunctionTypes": true,14 "noImplicitThis": true,15 "noUnusedLocals": true,16 "noUnusedParameters": true,17 "noImplicitReturns": true,18 "skipLibCheck": true,19 "noErrorTruncation": true,20 "outDir": "./dist",21 "rootDir": "./src",22 "baseUrl": ".",23 "stripInternal": true,24 },25 "exclude": ["node_modules"],26 "include": ["src/**/*"]27}
Selecting Your Bot Type.
Currently, Seyfert supports two types of applications: one based on the Discord gateway, which is the most commonly used, and another based on the Discord HTTP interaction system, which is less frequently used. It is important to understand the differences between these two types in order to choose the appropriate application for your needs.
- Gateway client receive all events from discord like messageCreate, interactionCreate, guildCreate, ready…
- The events that the client receive depends of the client intents.
- Unlike gateway, don’t receive events.
- Only execute commands with http request from discord.
Configuration
Once tsconfig.json
has been modified, we still have a few steps to go before we can run the application. In this case you need to tell seyfert your project’s structure:
so is necessary to create a file called seyfert.config.js
in the root folder of your project and add the following code:
1// @ts-check is better2const { config } = require('seyfert');3
4module.exports = config.bot({5 token: process.env.BOT_TOKEN ?? "",6 intents: ["Guilds"],7 locations: {8 base: "src",9 output: "dist", //If you are using bun, set "src" instead10 commands: "commands"11 }12});
1// @ts-check is better2const { config } = require('seyfert');3
4module.exports = config.http({5 token: process.env.BOT_TOKEN ?? "",6 applicationId: process.env.BOT_APP_ID,7 port: 3000, // by default is 80808 publicKey: process.env.BOT_PUBLIC_KEY,9 locations: {10 base: "src",11 output: "dist", //If you are using bun, set "src" instead12 commands: "commands"13 }14});
And let’s create the main file called index
in the src
folder and add the following code:
1import { Client } from 'seyfert';2
3const client = new Client();4
5// This will start the connection with the gateway and load commands, events, components and langs6client.start();
1import { HttpClient } from 'seyfert';2
3const client = new HttpClient();4
5// This will start listening to `https://yourweb.xyz/interactions` and load commands, components and langs6client.start();
So after complete these steps, your project structure should look like this:
Directorysrc
Directorycommands/
- …
- index.ts
- seyfert.config.js
- package.json
- .env
- tsconfig.json