from dotenv import dotenv_values from discord.ext import commands import discord import os import scrape_lexicanum config = { **dotenv_values(".env"), **os.environ, } intents = discord.Intents.default() intents.message_content = True bot = commands.Bot(command_prefix="Sigmar! ", intents=intents) @bot.command() async def ping(ctx): await ctx.send("pong") @bot.command(name="Explain", aliases=["explain", "What's", "what's"]) async def explain(ctx, *args): query = " ".join([x.replace('"', "") for x in args]) try: search_content = scrape_lexicanum.get_search_response(config, query) page_header, page_content, page_img_link = scrape_lexicanum.get_page_content(config, search_content[0]) embed = discord.Embed( title=page_header, description=search_content.pop(0), color=discord.Colour.blurple(), ) string_results = " ".join(str(x) for x in search_content) embed.add_field(name="Overview", value=page_content) embed.add_field(name="You May Have Meant", value=string_results) if page_img_link: embed.set_image(url=page_img_link) await ctx.send(embed=embed) except scrape_lexicanum.WikiError as e: await ctx.send(f"{e}") except Exception as e: print(f"Could not complete explanation: {e}") await ctx.send("Something has gone most terribly wrong...") bot.run(config['token'])