如何制作天气命令? 不和谐.py

问题描述

所以我在下面创建了这个天气命令,但由于某种原因,它只说机器人正在输入,并且出现错误。这是代码

import requests

@client.command()
async def weather(ctx,*,city: str):
    city_name = city
    complete_url = base_url + "appid=" + api_key + "&q=" + city_name
    response = requests.get(complete_url)
    x = response.json()
    channel = ctx.message.channel
    if x["cod"] != "404":
        async with channel.typing():
            y = x["main"]
            current_temperature = y["temp"]
            current_temperature_celsiuis = str(round(current_temperature - 273.15))
            current_pressure = y["pressure"]
            current_humidity = y["humidity"]
            z = x["weather"]
            weather_description = z[0]["description"]
            weather_description = z[0]["description"]
            embed = discord.Embed(title=f"Weather in {city_name}",color=ctx.guild.me.top_role.color,timestamp=ctx.message.created_at,)
            embed.add_field(name="Descripition",value=f"**{weather_description}**",inline=False)
            embed.add_field(name="Temperature(C)",value=f"**{current_temperature_celsiuis}°C**",inline=False)
            embed.add_field(name="Humidity(%)",value=f"**{current_humidity}%**",inline=False)
            embed.add_field(name="Atmospheric Pressure(hPa)",value=f"**{current_pressure}hPa**",inline=False)
            embed.set_thumbnail(url="https://i.ibb.co/CMrsxdX/weather.png")
            embed.set_footer(text=f"Requested by {ctx.author.name}")
        await channel.send(embed=embed)
    else:
        await channel.send("City not found.")

但是我从中得到的错误是说“main”是一个关键错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)