jaraco / irc

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

After joining a channel, how do I get a list of usernames? #207

Open MrBruz opened 1 year ago

MrBruz commented 1 year ago

Im trying connection.names() after I join the channel (run the join function) but its returning None

OrpheusGr commented 1 year ago

I believe connection.names() sends the command to the server, you probably need to make use of the "namreply" event to get the reply.

If you are using the SingleServerIRCBot or the SimpleIRCClient class, you can just add

def on_namreply(self, connection, event):
    #code here

to your code

Otherwise (if you're using the Reactor class) you probably gotta use add_global_handler() on a ServerConnection object:

e.g

def yourmethodnamehere(self, connection, event):
    #code here

x = irc.client.Reactor()
y = x.server()
y.add_global_handler("namreply", yourmethodnamehere)
y.connect(serverhere, porthere, nickhere)

P.S i assume connection.names() takes the channel name as an argument but i'm not sure.

P.S 2 You may need to use connection.names() within the on_join event cause i'm not sure that by calling it right after doing connection.join("#chan") there is enough time for the client to join #chan. In other words you might be sending NAMES too soon, before actually joining the channel.