The while loop I have in my program doesn’t execute a few lines of code

The while loop that I have in my discord.py bot program doesn’t execute a few lines of code. I’m trying to make it so that the loop breaks everytime countdown (aka the number of messages sent to a user) equals the limit (aka the number of messages I want sent to the user), however I’ve noticed that the bot keeps sending messages even if the countdown reaches the limit. I am getting absolutely no error messages.

From what I know, the problem is in the code below. But I can’t figure out where or what it is:

@bot.command(pass_context = True)
async def spm_dm(ctx, user : discord.Member):
    countdown = 0
    await  ctx.send(":white_check_mark:")
    while True:
        await user.send(f'{content}')
        countdown = countdown+1
        if countdown == limit:
            await ctx.send("The loop has been broken, reason: timeout")
            break
        else:
            continue

Answer

Use for loop as it will run the given limit times.

code for for loop:

@bot.command(pass_context = True)
async def spm_dm(ctx, user : discord.Member):
    countdown = 0
    await  ctx.send(":white_check_mark:")
    for i in range(0,limit):
        await user.send(f'{content}')
    await ctx.send("The loop has been broken, reason: timeout")

and if you want to use same code with while loop then:

@bot.command(pass_context = True)
async def spm_dm(ctx, user : discord.Member):
    countdown = 0
    await  ctx.send(":white_check_mark:")
    while countdown <= limit:
        await user.send(f'{content}')
        countdown = countdown+1
    await ctx.send("The loop has been broken, reason: timeout")