Saltearse al contenido

Extendiendo el archivo de configuración

Podrías tener una configuración como la siguiente:

import {
const config: {
bot(data: RuntimeConfig): InternalRuntimeConfig;
http(data: RuntimeConfigHTTP): InternalRuntimeConfigHTTP;
}
config
} from "seyfert";
export default
const config: {
bot(data: RuntimeConfig): InternalRuntimeConfig;
http(data: RuntimeConfigHTTP): InternalRuntimeConfigHTTP;
}
config
.
function bot(data: RuntimeConfig): InternalRuntimeConfig

Configurations for the bot.

@paramdata - The runtime configuration data for gateway connections.

@returnsThe internal runtime configuration.

bot
({
locations: RCLocations
locations
: {
RCLocations.base: string
base
: "dist",
RCLocations.commands?: string
commands
: "commands",
},
token: string
token
:
var process: NodeJS.Process
process
.
NodeJS.Process.env: NodeJS.ProcessEnv

The process.env property returns an object containing the user environment. See environ(7).

An example of this object looks like:

{
TERM: 'xterm-256color',
SHELL: '/usr/local/bin/bash',
USER: 'maciej',
PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
PWD: '/Users/maciej',
EDITOR: 'vim',
SHLVL: '1',
HOME: '/Users/maciej',
LOGNAME: 'maciej',
_: '/usr/local/bin/node'
}

It is possible to modify this object, but such modifications will not be reflected outside the Node.js process, or (unless explicitly requested) to other Worker threads. In other words, the following example would not work:

Terminal window
node -e 'process.env.foo = "bar"' && echo $foo

While the following will:

import { env } from 'node:process';
env.foo = 'bar';
console.log(env.foo);

Assigning a property on process.env will implicitly convert the value to a string. This behavior is deprecated. Future versions of Node.js may throw an error when the value is not a string, number, or boolean.

import { env } from 'node:process';
env.test = null;
console.log(env.test);
// => 'null'
env.test = undefined;
console.log(env.test);
// => 'undefined'

Use delete to delete a property from process.env.

import { env } from 'node:process';
env.TEST = 1;
delete env.TEST;
console.log(env.TEST);
// => undefined

On Windows operating systems, environment variables are case-insensitive.

import { env } from 'node:process';
env.TEST = 1;
console.log(env.test);
// => 1

Unless explicitly specified when creating a Worker instance, each Worker thread has its own copy of process.env, based on its parent thread's process.env, or whatever was specified as the env option to the Worker constructor. Changes to process.env will not be visible across Worker threads, and only the main thread can make changes that are visible to the operating system or to native add-ons. On Windows, a copy of process.env on a Worker instance operates in a case-sensitive manner unlike the main thread.

@sincev0.1.27

env
.
string | undefined
TOKEN
!,
});

Por ejemplo, al agregar algunas propiedades.

declare module 'seyfert' {
interface ExtendedRC {
prefix: string;
// incluso más propiedades
}
}

Notarás un error de tipo en tu archivo seyfert.config.ts.

Si no ves este error, tal vez omitiste un paso.

O ya tenías la propiedad prefix incluida.

Ventana de terminal
Property 'prefix' is missing in type '{ locations: ...

¡GENIAL! Entonces… ¿cómo obtengo la propiedad?

Tan simple como:

const rc = await client.getRC();
console.log(rc.prefix);

¿Qué pasa con las ubicaciones?

declare module 'seyfert' {
interface ExtendedRCLocations {
music: string;
}
}

¡GENIAL! Entonces…

const rc = await client.getRC();
console.log(rc.locations.music);

El producto terminado sería algo como esto:

import { config } from "seyfert";
export default config.bot({
locations: {
base: "dist",
commands: "commands",
music: "lavalink", // dist/lavalink
},
token: process.env.TOKEN!,
prefix: "s!",
});