Skip to content

How to write a plugin

It happens that you are missing something... And plugins can help you with this!

Example

ts
import { 
Plugin
,
Bot
} from "gramio";
export class
PluginError
extends
Error
{
wow
: "type" | "safe" = "type";
} const
plugin
= new
Plugin
("gramio-example")
.
error
("PLUGIN",
PluginError
)
.
derive
(() => {
return {
some
: ["derived", "props"] as
const
,
}; }); const
bot
= new
Bot
(
process
.
env
.
TOKEN
!)
.
extend
(
plugin
)
.
onError
(({
context
,
kind
,
error
}) => {
if (
context
.
is
("message") &&
kind
=== "PLUGIN") {
console
.
log
(
error
.
wow
);
} }) .
use
((
context
) => {
console
.
log
(
context
.
some
);
});

Scaffolding the plugin

This command will help you create a plugin with GramIO the easiest way.

bash
npm create gramio-plugin ./plugin
bash
yarn create gramio-plugin ./plugin
bash
pnpm create gramio-plugin ./plugin
bash
bun create gramio-plugin ./plugin

Supported environment