Skip to content

Plugin Development

Arnab Paryali edited this page Dec 11, 2021 · 1 revision

Creating a plugin for LazyBot is super easy if you have basic JS and GramJS knowledge.

All plugins are stored inside the plugins (src/plugins) folder. You can create a Typescript/Javascript file. Example : hello.ts , hello.js

// Type Referance
interface LBPlugin extends NewMessageInterface {
  handler: (event: NewMessageEvent, client: TelegramClient) => Promise<void>;
  commands?: string | string[];
  allowArgs?: boolean;
}

Breakdown

  • handler: A handler is a function that accepts two args - event and client.

    • event : event is an object containing the update information of type NewMessageEvent.
    • client : client is TelegramClient instance, most powerful object in LazyBot. You can do kinds of stuff that can't be done with the event object, everything that is possible with GramJS. (Referenace)
  • commands:

    • Command can be a single string or array of strings. Example : 'hello' , ['hello', 'hi'].
    • Command should not contain command prefix. Example : 'hello' ✅ , '.hello' ❌ .
  • allowArgs: Accepts boolean, If your command can accept args or not. Example: '.afk Hello' will work when allowArgs is true, but it won't respond if allowArgs is false

  • pattern: Accepts regex. Useful for incoming messages.

Each plugin object should have either `commands` or `pattern`

Clone this wiki locally