Cog File
unknown
python
a year ago
660 B
3
Indexable
Never
from discord.ext import commands from discord import app_commands import requests import os class weather(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot @app_commands.command() async def weather(ctx,*,location): data = requests.get(f'https://api.openweathermap.org/data/2.5/weather?q={location}&appid={os.getenv("api_key")}&units=metric') weather_data = data.json() temperature = weather_data["main"]["temp"] await ctx.channel.send(f"The temperature is {temperature} degree celcius") async def setup(bot:commands.Bot) -> None: await bot.add_cog(weather(bot))