arctic_clerk
arctic_clerk

Reputation: 67

Discord.py while True loop

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.

Upvotes: 1

Views: 1875

Answers (1)

Łukasz Kwieciński
Łukasz Kwieciński

Reputation: 15689

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

import asyncio

while True:
    # ...
    await asyncio.sleep(900)

Upvotes: 3

Related Questions