对象没有属性追加

炼金术士

我正在使用 discord 模块制作一个 discord bot,但我没有使用异步功能的经验。

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

@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'
好奇的家伙

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

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

print(type(bal))

请确保类型是append要工作的列表

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章