要約
Discord.pyでBOTを作っているのですが
splatoon3のAPIのjsonを読み込むときにエラーが出て躓いてしまいます
実現したいこと
jsonを読み込みたいです
発生している問題・エラーメッセージ
該当部分は
python
1msg = "__【ステージ情報:**" + resp["results"]["rule"]["name"] + "**】__\n"
typeerror: list indices must be integers or slices, not str
該当のソースコード
python
1import discord 2import json 3import re 4import requests 5 6Intents = discord.Intents.default() 7Intents.members = True 8Intents.message_content = True 9Intents.reactions = True 10Intents.presences = True 11Intents.emojis = True 12client = discord.Client(intents=Intents) 13 14spla ={ 15 "ナワバリ" : "regular", 16 "ナワバリマッチ" : "regular", 17 "レギュラー" : "regular", 18 "レギュラーマッチ" : "regular", 19 "ガチマ(チャレンジ)" : "bankara-challenge", 20 "バンカラ(チャレンジ)" : "bankara-challenge", 21 "ガチマ" : "bankara-challenge", 22 "ガチマ(オープン)" : "bankara-open", 23 "バンカラ(オープン)" : "bankara-open", 24 "リグマ" : "bankara-open", 25 "フェス" : "fest", 26 "サーモンラン" : "coop-grouping-regular", 27 "今" : "now", 28 "次" : "next", 29 "全て" : "all" 30} 31 32 33 34@client.event 35async def on_ready(): 36 print('ログイン now!w {0.user}'.format(client)) 37 38@client.event 39async def on_message(message): 40 #Botのメッセージは無視 41 if message.author.bot: 42 return 43 44 spla_con = re.compile("(.+)の(.+)のステージ情報").search(message.content) 45 if spla_con: 46 if spla_con.group(1) in spla.keys() and spla_con.group(2) in spla.keys(): 47 48 battle_ID, time_ID = spla[spla_con.group(2)], spla[spla_con.group(1)] 49 resp = requests.get(f"https://spla3.yuu26.com/api/{battle_ID}/{time_ID}") 50 resp = json.loads(resp.text) 51 msg = "__【ステージ情報:**" + resp["results"]["rule"]["name"] + "**】__\n" 52 for f in resp["stages"]: 53 msg += f["name"] + ":**" + f["id"] + "**\n" 54 55 await message.reply(msg) 56 57client.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 },
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/10/12 14:06
2022/10/12 14:14
2022/10/22 00:35