didier/cogs/slash/google_slash.py

24 lines
805 B
Python
Raw Normal View History

from discord.ext import commands
2022-02-03 01:43:54 +01:00
from discord.commands import slash_command, ApplicationContext, Option
from functions.scrapers.google import google_search, create_google_embed
from startup.didier import Didier
class GoogleSlash(commands.Cog):
def __init__(self, client: Didier):
self.client: Didier = client
2022-02-03 01:43:54 +01:00
@slash_command(name="google", description="Google search")
async def _google_slash(self, ctx: ApplicationContext, query: Option(str, "Search query")):
result = google_search(query)
if not result.results:
2022-02-03 01:43:54 +01:00
return await ctx.respond("Er ging iets fout (Response {})".format(result.status_code))
embed = create_google_embed(result)
2022-02-03 01:43:54 +01:00
await ctx.respond(embed=embed)
def setup(client: Didier):
client.add_cog(GoogleSlash(client))