【发布时间】:2021-08-15 11:44:10
【问题描述】:
嗨,我正在尝试找出这个错误argument of type 'int' is not iterable 我基本上是在制作一个包含 10 个结果的编号列表。对于列表中的第一个结果,我想在数字 1. 之后添加一个皇冠
这是我的工作:
async def leaderboard(self, ctx):
"""Displays the top 10 members in the server"""
async with self.bot.pool.acquire() as conn:
res = await conn.fetch("SELECT user_id,lvl,xp,total_xp FROM levels WHERE guild_id = $1 ORDER BY GREATEST(total_xp) DESC LIMIT 10", ctx.guild.id)
#0: user_id, 1: lvl
mess = "Here is a list of the current top ten active members."
x = 1
crown = f":crown: {x}" if 1 in x else f"{x}" #type int error happens here
for ele in res:
user = self.bot.get_user(int(ele[0]))
mess +="**{}.** {} on **Level {: <3}** with **{: <4} XP**\n\n".format(crown,user.name,ele[1], ele[2])
x+=1
embed = discord.Embed(title="Leaderboard", description=f"{mess}")
await ctx.send(embed=embed)
错误似乎发生在crown = f":crown: {x}" if 1 in x else f"{x}"这一行
帮助表示赞赏。
【问题讨论】:
-
x是一个数字,你对1 in x有什么期望? -
如果列表中的数字是 1,那么将
:crown:放在该数字前面就是我要在这里实现的目标。 -
什么列表? x 是一个单一的数字,
1,它是您在出错的那一行之前分配的。 -
上面的代码创建了一个编号从 1 到 10 的结果列表我想在列表中识别数字 1 并在该数字前面添加一个皇冠。
-
也许确实如此,但 x 绝对不是那个列表。你试过调试吗?
标签: python python-3.x discord.py