python - IndexError:列表索引超出范围 discord.py
问题描述
好的,所以我尝试制作一个 lvl 系统并且它到目前为止工作,但现在我想制作一个命令,它在嵌入中显示 lvl 和 xp。
但我得到一个错误IndexError: list index out of range
我这样定义我的xp和lvl
async def lvl_up(self, user):
cur_xp = user['xp']
cur_lvl = user['lvl']
并想像这样将其发送到嵌入中
embed=discord.Embed()
embed.add_field(name="Level", value=user[0]['lvl'], inline=True)
embed.add_field(name="XP", value=user[0]['xp'], inline=True)
await ctx.send(embed=embed)
但这些价值观不像我认为的那样工作......
解决方案
通常,索引超出范围错误仅表示您要求的索引不存在。所以这意味着:
value=user[0]['lvl']
可能是问题,因为它找不到用户的索引 0。
推荐阅读
- python - Numpy - 使用值作为另一个数组的索引
- c++ - ParseFromArray 函数在 C++ 中如何工作以及如何使用它来将二进制文件读入 protobuf?
- python - 使用依赖规则匹配的方面意见提取中的命名实体识别
- c# - 单元测试时间触发的 Azure 函数
- python - gcloud app deploy 遇到 SSL 错误
- java - Spring Boot JPA 删除返回 200ok 但不从数据库中删除
- flutter - Flutter - 迭代对象值
- r - 如何处理 R 中矩阵中的无限值?
- jquery - 尝试导入引导程序时出现vuejs jquery问题
- tcl - TCL - 将十六进制数转换为 ASCII 字符串