class Anjani

Abstract class of anjani bot, the main thing to run everything.


  • command_predicate - A ~pyrogram.filter.Filter predicate for the ~Anjani.on_command.

  • dispatch_event - Dispatch events to the ~Anjani.listeners.

  • dispatch_missed_events - Catchup missed events while the bot offline. (Can only run when the bot is not running)

  • idle - A ~pyrogram.idle mirror.

  • init_and_run - Initialize the bot and start it.

  • init_client - Initialize the ~pyrogram.Client.

  • load_all_plugins - Load all plugins from anjani/plugins.

  • load_plugin - Load a plugin from anjani/plugins.

  • log_stat - Log the bot's statuses into database.

  • on_command - All commands will be handled by this method.

  • redact_message - Redact sensitive messages.

  • register_command - Register a ~anjani.command.Command.

  • register_commands - Register iterable ~anjani.command.Command.

  • register_listener - Register a ~anjani.listener.Listener.

  • register_listeners - Register iterable ~anjani.listener.Listener.

  • reload_plugin_pkg - Reload a ~anjani.plugin.Plugin from anjani/plugins.

  • respond - Respond to a command that received from ~Anjani.on_command.

  • run - Run the bot.

  • start - Start the bot.

  • stop - Stop the bot gracefully.

  • unload_all_plugins - Unload all ~Anjani.plugins.

  • unload_plugin - Unload a ~anjani.plugin.Plugin.

  • unregister_command - Unregister a ~anjani.command.Command.

  • unregister_commands - Unregister iterable ~anjani.command.Command.

  • unregister_listener - Unregister a ~anjani.listener.Listener.

  • unregister_listeners - Unregister iterable ~anjani.listener.Listener.

  • update_plugin_event - Update a ~anjani.plugin.Plugin ~anjani.listener.Listener.

  • update_plugin_events - Register ~pyrogram.handlers.handler.Handler into the bot.


  • chats_languages (dict) - A mapping of chats and their languages settings.

  • client (~pyrogram.Client) - Pyrogram Client, the main means for interacting with Telegram.

  • commands (Dict of ~anjani.command.Command) - A mapping of commands and their respective classes.

  • config (~anjani.util.Config): The loaded configuration of the bot.

  • db (Abstract Class ~anjani.util.Database) - The database of the bot.

  • devs (Set of int) - A set of the IDs of the developers of the bot that configured.

  • events_activated (int) - The number of activated listener of ~pyrogram.handlers.handler.Handler.

  • http (~aiohttp.ClientSession) - aiohttp client sessions for making HTTP requests.

  • languages (dict) - A mapping of current supported languages file from anjani/languages.

  • listeners (Dict of ~anjani.listener.Listener) - A mapping of listeners and their respective classes that used in ~anjani.plugin.Plugin.

  • loaded (bool) - Whether the bot is initialized or not.

  • log (~logging.Logger) - Python Logging Module, the main way to log things.

  • loop (~asyncio.AbstractEventLoop) - Abstract base class for asyncio-compliant event loops.

  • owner (int) - The ID of the owner of the bot that configured.

  • plugins (Dict of ~anjani.plugin.Plugin) - Mapping of all loaded plugins and their respective classes.

  • staff (Set of int) - A set of the IDs of the staff of the bot that configured.

  • start_time_us (int) - The time when the bot started.

  • stopping (bool) - Whether the bot currently is on stopping or not.

  • uid (int) - Unique identifier for this bot.

  • user (~pyrogram.types.User) - A ~pyrogram.types.User object for the bot.

Must Read!

Using HTTP Request

Anjani has already set up and provide aiohttp Client when the bot initialized. simply use it by ~Anjani.http. Here are the example of HTTP request:

async with"") as r:  # here is `~Anjani`
    res = await r.json()  # returns dict
    await message.reply_text(res["slideshow"]["author"])


  • If you wan't to use aiohttp request use it from ~Anjani.http, DON'T CREATE A NEW SESSION since it will close the session that already initialized and bring you to a RuntimeError because the session has closed.

  • Using requests and urllib is NOT RECOMENDED because in case the request takes to long it will block the event loop.

    In asynchronous programming, blocking is all functions that are not await, but not all blocking forms are bad when it isn't blocking function excessively. Using blocking calls is inevitable, but if you block for too long then your bot will freeze since it has not stopped the function’s execution at that point to do other things.