Discord.py while True loop

Question:

I try to update multiple messages sent from the bot in a while true loop with a 15minutes sleep

@commands.cooldown(1, 30, commands.BucketType.user)
@bot.command()
async def updater(ctx):
    embed = discord.Embed(title="Title")
    
    msg = await ctx.send(embed=embed)
    all_stock.append(msg)

    while True:
        embed = discord.Embed(title="Title")
        await msg.edit(embed=embed)
        time.sleep(900)

but as soon as I run the function other commands don’t work anymore. I already tried to create a separate thread but it didn’t worked because of some async issues.

Asked By: arctic_clerk

||

Answers:

Other commands don’t work because time.sleep is blocking, you should use asyncio.sleep instead

import asyncio

while True:
    # ...
    await asyncio.sleep(900)
Answered By: Łukasz Kwieciński
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.