jaraco / irc

Full-featured Python IRC library for Python.
MIT License
390 stars 84 forks source link

Receive public messages #229

Closed rmblau closed 1 month ago

rmblau commented 2 months ago

While using AioSimpleIRCClient how can I receive public messages in a channel? I do not see any obvious way of doing this. I am using the irccat-aio example as a base. Thanks in advance!

ahopelesshadow commented 2 months ago

Create an event handler in your main bot file. something like the following,

from events import onpubmsg
server.add_global_handler("pubmsg", on_pubmsg)

and then in events.py create the on_pubmsg function.

def on_pubmsg(server, event):
    "Event fired when client receives a message from a channel"
    print(event)
    server.privmsg(event.target, " ".join(event.arguments))