Jump to content

Async Python message listening

Recommended Posts


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()

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


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

Share this post

Link to post
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):
new_loop = asyncio.new_event_loop()
t = Thread(target=start_loop, args=(new_loop,))


Edited by Stalkerx777

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now