#Cog must derive from Cog
1 messages · Page 1 of 1 (latest)
from disnake.ext import commands
from disnake import Embed, Color, CommandInteraction
import requests
from bs4 import BeautifulSoup
# Thanks GeeksForGeeks for this chunk of code: https://www.geeksforgeeks.org/how-to-extract-weather-data-from-google-in-python/
#######
def get_weather_data(location):
url = "https://www.google.com/search?q="+"weather"+location
html = requests.get(url).content
soup = BeautifulSoup(html, "html.parser")
temp = soup.find('div', attrs={'class': 'BNeawe iBp4i AP7Wnd'})
data = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text.split("\n")
if temp != None:
return (temp, data[0], data[1], url)
else:
return ("Failed to load data", "Failed to load data", "Failed to load data", url)
#######
class weatherCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.cooldown(1, 25, commands.BucketType.user)
@commands.slash_command(name="weather", description="Display a locations current weather")
async def weather(inter:CommandInteraction, location:str, private=False):
await inter.response.defer()
weather = get_weather_data(location=location)
emb = Embed(title=f"Weather data for {location.capitalize()}", description="Current weather data", color=Color.dark_gold())
emb.add_field(name="Temperature", value=weather[0])
emb.add_field(name="Time", value=weather[1])
emb.add_field(name="Sky", value=weather[2])
emb.set_footer(text="The URL used for this data is: "+weather[3])
emb.set_author(name="Command Made by @Karsonthefoxx")
await inter.followup.send(embed=emb, ephemeral=private)
def setup(bot):
bot.add_cog(weatherCog(bot))
and the error
Traceback (most recent call last):
File "c:\Users\karso\program\weather_bot\tr.py", line 6, in <module>
b.add_cog("weather")
File "C:\Users\karso\AppData\Local\Programs\Python\Python311\Lib\site-packages\disnake\ext\commands\common_bot_base.py", line 293, in add_cog
raise TypeError("cogs must derive from Cog")
TypeError: cogs must derive from Cog
i just realized what i did wrong
you need load the cog file PY bot.load_extension("cogs.Filename")
^
Oh i doint see it ;/
It's alright, i probably should have marked this as solved
but to be completely honest, i dont know how
what you mean bro?
the solved tag
theres a command you run to add that tag, but i dont know the bots prefix
you need create a prefix