Understanding 'declare module'
This technique, known as Module Augmentation, is explained in more detail in the official TypeScript documentation.
In this section, we won't dive deeply into how it works, but we'll explain what's necessary to apply it correctly within Seyfert.
The following code snippets can be used in any TypeScript file in your project. However, it's recommended to place a single declare module 'seyfert'
in the main file src/index.ts
that contains everything your bot needs.
Clients
Seyfert provides several client types to instantiate your bot, which could cause confusion when referencing the client in different parts of your code. To avoid this, you can specify the client type you're using to TypeScript. Be sure to choose only one of the following three implementations:
Middlewares
To use your middlewares throughout the project, you need to inform TypeScript about their structure and composition. Export all middlewares from your code and provide them to Seyfert as follows:
This applies similarly to global middlewares, which are automatically executed on every command, even if they aren't explicitly specified in it.
If you're not yet familiar with middlewares, you can review their use cases and structure in their dedicated section.
Languages
To correctly configure types for languages, it's recommended to establish a primary or base language that you always update. This way, all types will derive from this language, making it easier to keep the rest of the translations up to date.
Although you can use .json
files to store languages, it's highly recommended to use .ts
or .js
files. This allows you to include functions and benefit from autocomplete!
If you didn't know that Seyfert has an automatic language system, we recommend visiting the dedicated section on this.
Contexts
We often need to extend contexts to add useful properties or methods, which also requires updating the types.
If you've used extendContext
for this, you can use the following code to infer the type returned by your function and add it to the context:
If you're not yet familiar with how Seyfert allows you to easily modify and extend the context, you can review its dedicated section.
Command Properties
We often need to categorize some commands or simply assign an identifier for something.
To achieve this, we can use ExtraProps
:
Internal Options
Since Seyfert supports various modes of operation, it's necessary to add types as required by your implementations. For this, InternalOptions
exists as an interface designed to include properties that transform Seyfert types into something more comprehensive.
withPrefix
Setting this property to true
tells Seyfert that the context can include either a message or an interaction, both of which will be optional. By default, .interaction
is always present in the context.
asyncCache
Setting this property to true
tells Seyfert whether the cache will return a promise. By default, Seyfert uses MemoryAdapter
, a RAM cache that doesn't return promises, while RedisAdapter
does.
Configuration
In Seyfert, you can add more properties to the configuration file seyfert.config.mjs
, regardless of whether you're using the http
or bot
configuration. This can be done using ExtendedRC
as follows:
Locations
Just as you can extend Seyfert's base configuration, you can also extend the folder locations object using ExtendedRCLocations
. This can be done as follows: