import nextcord from nextcord.ext import commands, application_checks from nextcord import TextInputStyle import traceback import random import aiosqlite as sqlite3 import aiohttp from urllib.parse import urlparse import os import sys errormsg = ["Well maybe this won't happen next time"] class error(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot @commands.Cog.listener('on_application_command_error') async def errorhandler(self, interaction: nextcord.Interaction, error: nextcord.DiscordException): error = traceback.format_exception(type(error), error, error.__traceback__) random.shuffle(errormsg) strerror = "".join(error) print(strerror, file=sys.stderr) message = f"{errormsg[0]}\n```py\n{strerror[-1800:]}\n```\n Contact <@{self.bot.owner_id}> if the error persists" try: await interaction.response.send_message(message, ephemeral=True) except: await interaction.followup.send(message, ephemeral=True) def setup(bot: commands.Bot): bot.add_cog(error(bot))