https://github.com/x7007x/telebotplugins
A simple plugin system for pyTelegramBotAPI (telebot) that allows you to organize your bot's functionality into separate plugin files without having to redefine the bot instance in each file.
https://github.com/x7007x/telebotplugins
pypi-package python python3 telegram telegram-bots
Last synced: 18 days ago
JSON representation
A simple plugin system for pyTelegramBotAPI (telebot) that allows you to organize your bot's functionality into separate plugin files without having to redefine the bot instance in each file.
- Host: GitHub
- URL: https://github.com/x7007x/telebotplugins
- Owner: x7007x
- Created: 2025-03-03T14:10:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-29T14:04:41.000Z (over 1 year ago)
- Last Synced: 2025-08-16T15:53:03.714Z (11 months ago)
- Topics: pypi-package, python, python3, telegram, telegram-bots
- Language: Python
- Homepage: https://pypi.org/project/telebot-plugins/
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TeleBot Plugins
A simple plugin system for pyTelegramBotAPI (telebot) that allows you to organize your bot's functionality into separate plugin files without having to redefine the bot instance in each file.
## Features
- Load plugins from a specified directory
- Support for both synchronous and asynchronous telebot
- Handle relative paths properly
- Automatically register the bot instance globally
- Support for webhook and polling modes
## Installation
```bash
pip install telebot-plugins
```
## Usage
### Basic Example
```python
from telebot import TeleBot
from telebot_plugins import TelebotWithPlugins
# Create a bot instance
API_TOKEN = "YOUR_BOT_TOKEN"
bot = TeleBot(API_TOKEN)
# Initialize TelebotWithPlugins
plugins = TelebotWithPlugins(
bot=bot,
plugins="plugins", # plugins folder name
exclude=["disabled_plugin.py"] # files to exclude (optional)
)
if __name__ == '__main__':
# Start the bot
bot.polling()
```
### Example Plugin File (plugins/example.py)
```python
from telebot import bot # The bot is automatically available
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, "Hello! This is a plugin example.")
```
### Async Bot Example
```python
from telebot.async_telebot import AsyncTeleBot
from telebot_plugins import TelebotWithPlugins
import asyncio
# Create an async bot instance
API_TOKEN = "YOUR_BOT_TOKEN"
bot = AsyncTeleBot(API_TOKEN)
# Initialize TelebotWithPlugins
plugins = TelebotWithPlugins(
bot=bot,
plugins="plugins"
)
if __name__ == '__main__':
# Start the async bot
asyncio.run(bot.polling())
```