Discord bot together with this #392
-
I'm making a Discord bot that uses this library but I'm having some trouble doing the events. Code looks like this: @friendslist.on("friend_invite")
def fl_friend_invite(user):
print(f"New invite from {user.steam_id} ({user.name}), adding...")
friendslist.add(user)
@friendslist.on("friend_new")
def fl_friend_new(user):
print(f"New friend: {user.steam_id} ({user.name})!")
@client.event
async def on_ready():
print("[Discord] Client ready")
login() # This logs in to steam
if __name__ == "__main__":
client.run(discord_token, bot=True) If you need more info to help me please ask because I'm completely lost. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Yes, you need to give gevent loop a change to run. If you don't monekypatch, or call gevent cooperative function, the loop will never run. Mixing gevent and async and other, can be problematic. You should never try to monkey patch if you are mixing, because it will most likely break stuff. The only alternative is give a chance to each one to run. Since you are mainly running the discord client, setup a method that runs on a short interval and calls |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for the tip. I did not understand how to use the gevent thing and found this topic. I am getting a lot of noise like:
Is this expected? |
Beta Was this translation helpful? Give feedback.
Yes, you need to give gevent loop a change to run. If you don't monekypatch, or call gevent cooperative function, the loop will never run. Mixing gevent and async and other, can be problematic. You should never try to monkey patch if you are mixing, because it will most likely break stuff. The only alternative is give a chance to each one to run. Since you are mainly running the discord client, setup a method that runs on a short interval and calls
client.idle()
. The call will block and run any outstanding gevent work and return. Avoid making any long blocking calls like computation or non-gevent cooperative io (e.g. unpatchedrequests
).