![](/img/trans.png)
[英]I'm a little confused with strings and integers, and I keep getting this error: TypeError: list indices must be integers or slices, not str
[英]I keep getting this error: list indices must be integers or slices, not str
我正在嘗試運行此命令,但是,每次運行時,我都會收到此錯誤:“列表索引必須是整數或切片”。 有人能幫我嗎?
這是我的代碼:
skins = ""
data = requests.get("https://benbotfn.tk/api/v1/cosmetics/br").json()["items"]
for x in data:
if x["backendType"] == "AthenaCharacter":
skins = skins + x["name"] + ":" + "\n" + x["id"] + "\n"
if skins == "":
skins = "None"
@client.command()
async def skin(ctx):
await ctx.send(skins)
你獲取數據的方式是錯誤的應該是這樣的,並且在它自己的命令中。 請記住,如果您運行它,您將收到錯誤消息,您不能發送超過 2000 個字符的消息。
@bot.command()
async def skin(ctx):
skins = []
for x in data:
if x["backendType"] == "AthenaCharacter":
skins.append(f'{x["name"]}: {x["id"]}')
print(skins[0:3]) # just to show it works print the first elements
await ctx.send('\n'.join(skins))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.