对象没有附加属性

2024-04-18 19:06:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用discord模块制作一个discord机器人,但我没有使用异步函数的经验

下面是代码中不起作用的部分:

@client.command()
async def bank(ctx):
    global bal
    if ctx.author.name in users:
        bal.append(0)
    else:
        print("nope")
    print(bal)

bal以前设置为所有函数之外的空列表

它返回一个巨大的错误,但主要是:

AttributeError: 'Command' object has no attribute 'append'

Tags: 模块函数代码clientasyncdef机器人经验
1条回答
网友
1楼 · 发布于 2024-04-18 19:06:23

读取错误AttributeError: 'Command' object has no attribute 'append',看起来bal变量的类型是object而不是列表

您可以通过检查if语句之前的类型来验证这一点,如下所示:

print(type(bal))

请确保类型为列表,以便append工作

相关问题 更多 >