【发布时间】:2021-08-04 18:09:40
【问题描述】:
@client.command(aliases=["lb"])
async def leaderboardie(ctx, x=1):
users = await get_bank_data()
leader_board = {}
total = []
for user in users:
name = int(user)
total_amount = users[user]["wallet"] + users[user]["bank"]
leader_board[total_amount] = name
total.append(total_amount)
total = sorted(total, reverse=True)
em = discord.Embed(title=f"Top {x} Richest People",
description="This is decided on the basis of raw money in the bank and wallet", color=discord.Color(0xfa43ee))
index = 1
for amt in total:
id_ = leader_board[amt]
member = client.get_user(id_)
name = member.name
em.add_field(name=f"{index}. {name}", value=f"{amt}", inline=False)
if index == x:
break
else:
index += 1
await ctx.send(embed=em)
我不断收到错误:
Command raised an exception: AttributeError: 'NoneType' object has no attribute 'name'
它基本上是关于基于用户钱包的排行榜,但每次我出于某种原因收到此错误,如果您知道解决方案,请告诉我。
【问题讨论】:
-
client.get_user(id_)正在返回None。 -
如何解决它
-
要么跳过该成员,要么输入替换值,或者以其他方式获取名称。想想你希望你的程序在那种情况下做的事情,然后编写执行此操作的代码。
标签: python python-3.x discord discord.py