Home > Software design >  How can I fix this error? | Discord.Py Bot
How can I fix this error? | Discord.Py Bot

Time:06-13

How do I can fix this error? I get this error when i try to start the bot.

    if name == None:
    ^
IndentationError: expected an indented block

My Full Code:

@bot.command()
async def gen(ctx,name=None):
    role = discord.utils.find(lambda r: r.name == 'VIP ACCESS', ctx.guild.roles)
    if role in ctx.author.roles:
    if name == None:
        await ctx.send("Specify The Brand You Want! `{prefix}stock`")
    else:
        name = name.lower() ".txt"
        if name not in os.listdir("Accounts"):
            await ctx.send(f"Account Does Not Exist! `{prefix}stock`")
        else:
            with open("Accounts\\" name) as file:
                lines = file.read().splitlines()
            if len(lines) == 0:
                await ctx.send("These Accounts Are Out Of Stock! `{prefix}stock`")
            else:
                with open("Accounts\\" name) as file:
                    account = random.choice(lines)
                try:
                    await ctx.author.send(f"`{str(account)}`\n\nThis message will delete in {str(delete)} seconds!",delete_after=delete)
                except:
                    await ctx.send("Failed to send! Turn On Your Direct Messages!(In The Server Privacy Settings)")
                else:
                    await ctx.send("Sent The Account To Your DMS!")
                    with open("Accounts\\" name,"w") as file:
                        file.write("")
                    with open("Accounts\\" name,"a") as file:
                        for line in lines:
                            if line != account:
                                file.write(line "\n")
    else:
     await ctx.send("You haven't got access to use that command.")

Please help, how can I fix this?? I need help to fix this. I appreciate everyone's help

CodePudding user response:

if role in ctx.author.roles:
if name == None:

Needs to be changed to

if role in ctx.author.roles:
    if name == None:

And all indentation below until you reach the closing elif/else..

CodePudding user response:

In your gen function intent if-else block on 3-rd line

  • Related