I have twitch bot and discord bot. I would like to control the twitch bot via discord, and send some data from twitch bot to discord bot. For example, I would type "?unload xx" in discord and it would turn off some feature in the twitch bot. Another example is that after some twitch event, I would send data to discord bot, and discord bot would show it in channel. I was trying to run the discord bot, and then twitch bot in backgrond loop, but that didn't work. I was also trying to setup http server for webhooks, but that didn't work either. Is there something I am missing? I can't solve this problem. Thank's for help guys.
EDIT Both are in python, different files but imported to the main and run in one. I was trying asyncio, that was the discord bot and twitch in background, but I was getting "this event loop is already running" error. I was also trying discord bot and http server in differet threads, but it was working really weirdly, not responding sometimes, sometimes not event starting, turning off after while.
Here is threading way I've tried but didn't work
discord_bot = TestBot(command_prefix="?", intents=discord.Intents.default())
twitch_bot = Bot()
twitch_thread = threading.Thread(target=twitch_bot.run, daemon=True)
twitch_thread.start()
discord_bot.run(TOKEN)
According to the discord.Client.run
section from the discord.py API Reference:
This function must be the last function to call due to the fact that it is blocking. That means that registration of events or anything being called after this function call will not execute until it returns.
I recommend you to use discord.Client.start
instead of discord.Client.run
. It should work with asyncio
, assuming that twitch_bot.run
wouldn't block like how discord.Client.run
does.
loop = asyncio.get_event_loop()
loop.create_task(discord_bot.start(TOKEN))
loop.create_task(twitch_bot.run())
loop.run_forever()