我想尝试用 api 做祈祷时间,但我的问题是这样,你可以检查 api 链接,看看我做的是否失败或正确,请解决我的问题,因为我厌倦了.
@client.command()
@commands.guild_only()
async def prayers(ctx):
api = "http://api.aladhan.com/v1/timingsByCity?city=karlshamn&country=sweden&method=3&school=1"
response = requests.get(api)
result = response.json()
timings = result["data"]
fajr = timings["Fajr"]
dhuhr = timings["Dhuhr"]
asr = timings["Asr"]
maghrib = timings["Maghrib"]
isha = timings["Isha"]
embed = discord.Embed(title="Prayers time Karlshamn", colour=0xa02c2c)
embed.add_field(name="Fajr", value=fajr, inline=False)
embed.add_field(name="Dhuhr", value=dhuhr, inline=False)
embed.add_field(name="Asr", value=asr, inline=False)
embed.add_field(name="Maghrib", value=maghrib, inline=False)
embed.add_field(name="Isha", value=isha, inline=False)
await ctx.send(embed=embed)
错误
Ignoring exception in command prayers:
Traceback (most recent call last):
File "C:\Users\malaz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\malaz\Desktop\bot\bot.py", line 86, in prayers
fajr = timings["Fajr"]
KeyError: 'Fajr'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\malaz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\malaz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\malaz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: 'Fajr'
答案 0 :(得分:0)
你可以试试替换
SCNScene
与
struct MyView: View {
@State private var 2dscene = MyScene()
@State private var 3dScene = SCNScene(named: "MyFile")
var body: some View {
ZStack {
SceneView(scene: 3dScene)
SpriteView(scene: 2dscene)
}
}
}
因为fajr 和所有在时间字典中的祈祷