Jump to content

Async Python message listening


Spike

Recommended Posts

Hi,

i'm using an api whitch uses async and awake calls (i'm not that familiar with threading)  - the problem is that these calls are stopping/blocking my whole houdini interface from working

I'm connecting houdini with discord  by 

import discord

token = "xxxxxxxxxx"

client = discord.Client()

@client.event
async def on_message(message):
    print(message.content)
  
    messages = await channel.history(limit=123).flatten()
    if message.content.find("hello") != -1:
        await message.channel.send("hi back") 

client.run(token)

but this blocks my whole houdini application - the python script is running smoothly in the background (and works)

Hope you can help me! - really desperate at the moment that this is not working

 

if it i helps: discord api is using  asyncio to work with threads

Link to comment
Share on other sites

I assume you're using Python 3 build of Houdini-18? Not only it's not official yet but it's far from stable first of all. Second, if you look at the Discord API docs, it says that client.run() is blocking, meaning it's spawning an event loop that blocks the interpreter which runs on the main thread where the Houdini UI runs too.

You need to run your Discord client code on a separate thread. It's a big topic and far beyond the scope of Houdini.

From a random google page:

from threading import Thread
import asyncio
def start_loop(loop):
    asyncio.set_event_loop(loop)
    loop.run_forever()
new_loop = asyncio.new_event_loop()
t = Thread(target=start_loop, args=(new_loop,))
t.start()

 

Edited by Stalkerx777
typo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...