要約
Discord.pyでBOTを作っているのですが
splatoon3のAPIのjsonを読み込むときにエラーが出て躓いてしまいます
実現したいこと
jsonを読み込みたいです
発生している問題・エラーメッセージ
該当部分は
python
msg = "__【ステージ情報:**" + resp["results"]["rule"]["name"] + "**】__\n"
typeerror: list indices must be integers or slices, not str
該当のソースコード
python
import discord import json import re import requests Intents = discord.Intents.default()Intents.members = TrueIntents.message_content = TrueIntents.reactions = TrueIntents.presences = TrueIntents.emojis = Trueclient = discord.Client(intents=Intents) spla ={ "ナワバリ" : "regular", "ナワバリマッチ" : "regular", "レギュラー" : "regular", "レギュラーマッチ" : "regular", "ガチマ(チャレンジ)" : "bankara-challenge", "バンカラ(チャレンジ)" : "bankara-challenge", "ガチマ" : "bankara-challenge", "ガチマ(オープン)" : "bankara-open", "バンカラ(オープン)" : "bankara-open", "リグマ" : "bankara-open", "フェス" : "fest", "サーモンラン" : "coop-grouping-regular", "今" : "now", "次" : "next", "全て" : "all"} @client.eventasync def on_ready(): print('ログイン now!w {0.user}'.format(client)) @client.eventasync def on_message(message): #Botのメッセージは無視 if message.author.bot: return spla_con = re.compile("(.+)の(.+)のステージ情報").search(message.content) if spla_con: if spla_con.group(1) in spla.keys() and spla_con.group(2) in spla.keys(): battle_ID, time_ID = spla[spla_con.group(2)], spla[spla_con.group(1)] resp = requests.get(f"https://spla3.yuu26.com/api/{battle_ID}/{time_ID}") resp = json.loads(resp.text) msg = "__【ステージ情報:**" + resp["results"]["rule"]["name"] + "**】__\n" for f in resp["stages"]: msg += f["name"] + ":**" + f["id"] + "**\n" await message.reply(msg) client.run("TOKENHERE")
補足
python 3.10.14
API: https://spla3.yuu26.com/
リスポンスデータ例
{ "results": [ { "start_time": "2022-09-14T13:00:00+09:00", "end_time": "2022-09-14T15:00:00+09:00", "rule": { "key": "LOFT", "name": "ガチヤグラ" }, "stages": [ { "id": 3, "name": "ヤガラ市場", "image": "https://xxxxxxxx" }, { "id": 14, "name": "チョウザメ造船", "image": "https://xxxxxxxx" } ], "is_fest": false },
0 コメント