Skip to content

Loader usage

The usage is extremely simple, here we will show you how to use it, regardless of whether it is TypeScript or JavaScript.

const
const loader: Loader<Command<CommandOptions>>
loader
= new
new Loader<Command<CommandOptions>>(options: LoaderOptions): Loader<Command<CommandOptions>>

Create a new instance to load the commands.

Loader
({
/**
* Here are the file extensions of your commands, for example: “ts”, “js”, “cjs” or “mjs”.
* It is not necessary to specify all those files, actually just use the same extension as your index.
*/
LoaderOptions.extensions: {}

File extensions to load

extensions
: [ /* File extensions */ ],
LoaderOptions.path: string

Set the absolute path for your commands, for example: src/commands.

path
: './commands',
LoaderOptions.bot: {
token: string;
id: string;
}

The necessary bot information for the commands to be uploaded

bot
: {
id: string
id
:
any
process
.
any
env
['BOT_ID'],
token: string
token
:
any
process
.
any
env
['BOT_TOKEN']
}
});

This is included in your index, in a function, or wherever, as long as the file containing this is executed, everything will work. So as you may have noticed, you can use this code whatever you use, whether it is a .ts, .js, .cjs or .mjs file.

Example of your files

Suppose I put this in the index, now, your files should look something like this:

(Remember to choose the example based on whether you are using JavaScript or TypeScript)

  • package.json
  • tsconfig.json
  • Directorysrc
    • index.ts
    • Directorycommands