Skip to main content

Autoload commands plugin for GramIO

Works with
This package works with Bun
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
JSR Score
100%
Published
a week ago

@gramio/autoload

npm JSR JSR Score

Autoload commands plugin for GramIO.

Usage

full example

Important

Please read about Lazy-load plugins

Register the plugin

// index.ts
import { Bot } from "gramio";
import { autoload } from "@gramio/autoload";

const bot = new Bot(process.env.TOKEN as string)
    .extend(autoload())
    .onStart(console.log);

bot.start();

export type BotType = typeof bot;

Create command

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

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

Options

Key Type Default Description
pattern? string "**/*.{ts,js,cjs,mjs}" Glob patterns
path? string "./commands" the path to the folder
onLoad? (params: { absolute: string; relative: string }) => unknown the 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

Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @gramio/autoload

Import symbol

import * as mod from "@gramio/autoload";

Add Package

npx jsr add @gramio/autoload

Import symbol

import * as mod from "@gramio/autoload";

Add Package

yarn dlx jsr add @gramio/autoload

Import symbol

import * as mod from "@gramio/autoload";

Add Package

pnpm dlx jsr add @gramio/autoload

Import symbol

import * as mod from "@gramio/autoload";

Add Package

bunx jsr add @gramio/autoload

Import symbol

import * as mod from "@gramio/autoload";