繁体   English   中英

我该如何解决这个错误? | Discord.Py 机器人

[英]How can I fix this error? | Discord.Py Bot

我该如何解决这个错误? 当我尝试启动机器人时出现此错误。

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

我的完整代码:

@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.")

请帮忙,我该如何解决这个问题? 我需要帮助来解决这个问题。 我感谢大家的帮助

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

需要改为

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

以及下面的所有缩进,直到您到达结束的 elif/else..

在您的第 3 行的 gen 函数意图 if-else 块中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM