I have a background loop involving selenium, so it takes a long time to finish executing. I noticed that the bot had a delay when responding to commands, and I found out that the processes inside @tasks.loop() needs to finish before the commands execute. For example:
from discord.ext import commands, tasks
import time
bot = commands.Bot(command_prefix='-')
@bot.command()
async def test(ctx):
await ctx.send('hi')
@tasks.loop(seconds=30)
async def loop():
print('h')
time.sleep(20)
print('i')
@bot.event
async def on_ready():
loop.start()
bot.run()
Here, if you do -test after it prints the letter h and before it prints the letter i, the bot will not respond until it prints the i and the loop finishes.
How would I make it so that the commands will be able to execute along with the loop? FYI my code doesn't have a time.sleep(), it was just an example.