Python messenger bot aggregator, supporting Discord, Telegram, and potentially others
pip install botter==0.0.7
Botter is a framework which allows your bots run in any available messenger. Currently, there are only one implementation for Discord, but it is easy to implement other platforms.
Okay, let's get started!
At first, you should register a bot in the desired platform. As all messengers provide different ways to do so, we will not describe this process here.
Botter uses event-based architecture, with a most-common event - MessageEvent
.
Events are handled by EventHandler
's.
So, let's create out own:
from botter.api import *
from botter.api.handlers import *
class SimpleEchoHandler(ReplyHandler):
async def handle_message(self, message: InboundMessage) -> Message:
return Message(f"You've said:\n" + message.text)
Here we use the ReplyHandler
, which:
MessageHandler
MessageEvent
handle_message()
with the message from event.Message
rather than None,
ReplyHandler
would send it to server with a mention to the original message's author.Then we need to create a Bot
- object that aggregates handlers and mappings to the implementation.
Here we use discord driver as an example.
from botter.discord import DiscordBot
class EchoBot(Bot[DiscordBot]):
token = 'INSERT_YOUR_TOKEN_HERE'
event_handlers = [ SimpleEchoHandler ]
client = DiscordBot(token=token)
Okay, let's try it out!
Wow! It works!
Now, let's try to have some fun with the events.