【问题标题】:How to get the json data from api and send it in embed form in discord.py?如何从 api 获取 json 数据并将其以嵌入形式发送到 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
}
}

【问题讨论】:

    标签: python json discord.py


    【解决方案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 已编辑,这是您的意思吗?还有错误的消息吗?
    猜你喜欢
    • 2021-07-01
    • 2021-06-06
    • 2021-10-16
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    相关资源
    最近更新 更多