Skip to content

Autoload Plugin

npmJSRJSR Score

Plugin for autoload from files.

Installation

bash
npm install @gramio/autoload
bash
yarn add @gramio/autoload
bash
pnpm add @gramio/autoload
bash
bun install @gramio/autoload

Usage

full example

Register the plugin

ts
// index.ts
import { 
Bot
} from "gramio";
import {
autoload
} from "@gramio/autoload";
const
bot
= new
Bot
(
process
.
env
.
TOKEN
!)
.
extend
(
autoload
())
.
onStart
(
console
.
log
);
bot
.
start
();
export type
BotType
= typeof
bot
;

Create command

ts
// commands/command.ts
import type { BotType } from "..";

export default (bot: BotType) =>
    bot.command("start", (context) => context.send("hello!"));

Options

KeyTypeDefaultDescription
pattern?string"**/*.{ts,js,cjs,mjs}"Glob patterns
path?string"./commands"the path to the folder
onLoad?(params: { absolute: string; relative: string }) => unknownthe hook that is called when loading a file
onFinish?(paths: { absolute: string; relative: string }[]) => unknown;the hook that is called after loading all files

and other glob package options