Bot not working normally when multiple discord client instances run in different python applications #10025
Unanswered
homeboykeroro
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
I am creating two python applications (main1.py and main2.py). What I am trying to do is to create a discord bot in each of my python application (one bot per application), and each of my applications would call their own bot to send message to my discord channel (these two applications would send message to the same channel), and also periodically execute their complex function.
In order to keep executing functions periodically while running my discord bots in my applications, my idea is to start my bots in new threads in each of my application, and use while loop to keep running my complex function in main thread, so that my applications can perform the two works concurrently.
main1.py
|------ main thread (call main1's bot to send message, and periodically execute my complex function in while loop)
|------ main1_chatbot_thread (run discord bot with CHATBOT_TOKEN_1)
main2.py
|------ main thread (call main2's bot to send message, and periodically execute my complex function in while loop)
|------ main2_chatbot_thread (run discord bot with CHATBOT_TOKEN_2)
Problem
The problem is that when I run main1.py and main2.py together, my bots keep sending the same message of 'Starts scanner' multiple times and get stuck (not running code following the
send_message_by_list_with_response
function, socomplex_function
would not get executed), but if I just run main1.py or main2.py individaully my bot works normally. I just have no idea how should I troubleshoot this problem since I don't find any similar issue online.So I am just thinking does discord.py allows developer to start bot in a new thread? Would bots interfere with each other if I start my bots in this way?
Code Snippet
Here is my simpified code to demonstrate my idea, main1.py and main2.py code are very similar except for token, thread name and the function that would be called periodically (
complex_function
)main1.py
/main2.py
discord_chatbot.py
discord_message.py
It is just a wrapper class with getter and setter nothing is really special.
Beta Was this translation helpful? Give feedback.
All reactions