Python 对象没有附加属性
我正在用discord模块制作一个discord机器人,但我没有使用异步函数的经验 下面是代码中不起作用的部分:Python 对象没有附加属性,python,discord,discord.py,Python,Discord,Discord.py,我正在用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以前设置为所有函数之外的空列表 它返回一个巨大的错误,但主要是:
@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”对象没有属性“append”
,看起来bal
变量属于object
类型,而不是列表
您可以通过检查if语句之前的类型来验证这一点,如下所示:
print(type(bal))
请确保类型是list for
append
才能工作。错误是不言自明的:bal
必须是listtoappend
类型。如果出现该错误,则bal
不是列表。仔细检查以确保您没有意外地覆盖列表。错误似乎表明您有一个名为bal
的命令,该命令正在覆盖您的bal
列表