Reputation: 181
I have a discord bot that needs to run in a while(True) loop, as well as still receive commands. The only way I think I can do this that works with my program would be to have 2 separate instances of the bot running. Like saying:
client = commands.Bot(command_prefix = '!');
client2= commands.Bot(command_prefix = '.');
and then at the bottom:
client.run('TOKEN')
client2.run('TOKEN')
I tried this, and it didn't work. What am I doing wrong? Is there a way to run 2 bots, or the same bot twice from one script?
Upvotes: 1
Views: 4279
Reputation: 3495
You need to create your own event loop and run the bots with that, as client.run
is blocking.
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix='!')
client2 = commands.Bot(command_prefix='.')
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.create_task(client.start('TOKEN1'))
loop.create_task(client2.start('TOKEN2'))
loop.run_forever()
Upvotes: 8