如何从 api 获取 json 数据并将其以嵌入形式发送到 discord.py 中?
Posted
技术标签:
【中文标题】如何从 api 获取 json 数据并将其以嵌入形式发送到 discord.py 中?【英文标题】:How to get the json data from api and send it in embed form in discord.py? 【发布时间】:2022-01-08 14:45:14 【问题描述】:@commands.command() async def weather(self, ctx, msg):
querystring = "q":f"msg"
response = requests.request("GET", url, headers=headers, params=querystring)
response=response.json()
location=response["location" "name"]
Region=response.location().region
Country=response.location().country
Tempertaure=response.current().temp_c
Condition=response.current().condition().text
Winds=response.location().wind_kph
Windd=response.location().wind_degree
Winddir=response.current().vwind_dir
Humidity=response.current().humidity
Feelslike=response.current().feelslike_c
icon=response.current().condition().icon
weathere=discord.Embed(
title="Weather Informations ",
description=f"Weather information for the msg",
color=discord.Colour.random()
)
weathere.set_thumbnail(url= icon)
weathere.add_field(name="Location", value=f"location")
weathere.add_field(name="Region", value=f"Region")
weathere.add_field(name="Country", value=f"Country")
weathere.add_field(name="Tempertaure", value=(f"Tempertaure॰C"))
weathere.add_field(name="Condition", value=f"Condition")
weathere.add_field(name="Wind speed", value=f"Winds")
weathere.add_field(name="Wind Degree", value=()
weathere.add_field(name="Humidity", value=)
weathere.add_field(name="Feels ", value=)
weathere.add_field(name="Feels ", value=)
await ctx.send(embed=)
我想从 Json 格式中获取特定数据 数据如下:
2 items
"location":8 items
"name":"Kolkata"
"region":"West Bengal"
"country":"India"
"lat":22.57
"lon":88.37
"tz_id":"Asia/Kolkata"
"localtime_epoch":1638330237
"localtime":"2021-12-01 9:13"
"current":23 items
"last_updated_epoch":1638329400
"last_updated":"2021-12-01 09:00"
"temp_c":21
"temp_f":69.8
"is_day":1
"condition":...3 items
"wind_mph":6.9
"wind_kph":11.2
"wind_degree":350
"wind_dir":"N"
"pressure_mb":1016
"pressure_in":30
"precip_mm":0
"precip_in":0
"humidity":83
"cloud":0
"feelslike_c":21
"feelslike_f":69.8
"vis_km":2
"vis_miles":1
"uv":6
"gust_mph":11.4
"gust_kph":18.4
【问题讨论】:
【参考方案1】:那么,你的问题是什么?
weathere.add_field(name="Wind Degree", value=f"Windd")
weathere.add_field(name="Humidity", value=f"Humidity")
weathere.add_field(name="Feels ", value=f"Feelslike")
weathere.add_field(name="Feels ", value=f"response.current().feelslike_f")
await ctx.send(embed=weathere)
这对你有用吗?
【讨论】:
我没有从 api 获取数据到嵌入中? 值中应该有什么 @Abhishekkushwaha 已编辑,这是您的意思吗?还有错误的消息吗?以上是关于如何从 api 获取 json 数据并将其以嵌入形式发送到 discord.py 中?的主要内容,如果未能解决你的问题,请参考以下文章
如何从 Spotify Search API 获取数据并将其解析为 JSON? [在 node.js 中
如何从 PHP 中获取远程 JSON 或 XML API 数据并将返回对象分配为 PHP 变量?
如何从 JSON 获取数据以在 PrimeNG 折线图中使用?
如何在 Swift 中获取 JSON 数据并将其添加到 URL
如何使用 node.js MySQL 从 MySql DB 获取结果并将它们发送回 API.ai - DialogFlow