diff --git a/gameutils.py b/gameutils.py index 0e49ba2..d366903 100644 --- a/gameutils.py +++ b/gameutils.py @@ -4,6 +4,8 @@ from nextcord import TextInputStyle import random import aiosqlite as sqlite3 import aiohttp +import traceback +import sys from urllib.parse import urlparse import os @@ -37,6 +39,18 @@ class TurnModal(nextcord.ui.Modal): pass await interaction.followup.send(f"<@{self.fristrun.id}> it is now your turn!\n{self.text.value}") + async def on_error(self, error: nextcord.DiscordException, interaction: nextcord.Interaction): + error = traceback.format_exc() + print(error, file=sys.stderr) + message = f"```py\n{error[-1800:]}\n```\n Contact the bot owner if the error persists" + try: + await interaction.send(message, ephemeral=True) + except: + try: + await interaction.followup.send(message, ephemeral=True) + except: + await interaction.response.send_message(message, ephemeral=True) + class GameView(nextcord.ui.View): def __init__(self): @@ -79,6 +93,18 @@ class GameView(nextcord.ui.View): await interaction.response.send_modal(TurnModal(message,turnping,False)) return + async def on_error(self, error: nextcord.DiscordException, item: nextcord.ui.Item, interaction: nextcord.Interaction): + error = traceback.format_exc() + print(error, file=sys.stderr) + message = f"```py\n{error[-1800:]}\n```\n Contact the bot owner if the error persists" + try: + await interaction.send(message, ephemeral=True) + except: + try: + await interaction.followup.send(message, ephemeral=True) + except: + await interaction.response.send_message(message, ephemeral=True) + class gameutils(commands.Cog): def __init__(self, bot: commands.Bot): diff --git a/rolebuttons.py b/rolebuttons.py index 41fc7dc..2318f82 100644 --- a/rolebuttons.py +++ b/rolebuttons.py @@ -26,6 +26,18 @@ class RoleView(nextcord.ui.View): await interaction.response.send_message(f"Added <@&{role.id}> to you!", ephemeral=True, allowed_mentions=nextcord.AllowedMentions.none()) return + async def on_error(self, error: nextcord.DiscordException, item: nextcord.ui.Item, interaction: nextcord.Interaction): + error = traceback.format_exc() + print(error, file=sys.stderr) + message = f"```py\n{error[-1800:]}\n```\n Contact <@{self.bot.owner_id}> if the error persists" + try: + await interaction.send(message, ephemeral=True) + except: + try: + await interaction.followup.send(message, ephemeral=True) + except: + await interaction.response.send_message(message, ephemeral=True) + class rolebutton(commands.Cog): diff --git a/speechbubble.py b/speechbubble.py index cc64d55..b437a96 100644 --- a/speechbubble.py +++ b/speechbubble.py @@ -55,6 +55,19 @@ class ApplicationView(nextcord.ui.View): await interaction.response.edit_message(embed=embed, view=None) return + async def on_error(self, error: nextcord.DiscordException, item: nextcord.ui.Item, interaction: nextcord.Interaction): + error = traceback.format_exc() + print(error, file=sys.stderr) + message = f"```py\n{error[-1800:]}\n```\n Contact <@{self.bot.owner_id}> if the error persists" + try: + await interaction.send(message, ephemeral=True) + except: + try: + await interaction.followup.send(message, ephemeral=True) + except: + await interaction.response.send_message(message, ephemeral=True) + + class ApplicationModal(nextcord.ui.Modal): def __init__(self,user,bot): self.victim = user @@ -88,7 +101,7 @@ class ApplicationModal(nextcord.ui.Modal): ) print(self.image.value) if urlparse(self.image.value).netloc != 'media.discordapp.net' and urlparse(self.image.value).netloc != 'cdn.discordapp.com': - await interaction.send_message(f"for security reasons, the bot only accepts images from media.discordapp.net or cdn.discordapp.com", ephemeral=True) + await interaction.send(f"for security reasons, the bot only accepts images from media.discordapp.net or cdn.discordapp.com", ephemeral=True) return async with aiohttp.ClientSession() as session: async with session.get(self.image.value) as response: diff --git a/wordpress.py b/wordpress.py index 29ed37b..2b0880f 100644 --- a/wordpress.py +++ b/wordpress.py @@ -6,6 +6,8 @@ from random import randint import aiosqlite as sqlite3 import requests import json +import traceback +import sys from datetime import datetime import base64 from urllib.parse import urlparse @@ -75,6 +77,19 @@ class BlogModal(nextcord.ui.Modal): responce = requests.post(self.endpoint, headers=header, json=post) await interaction.response.send_message(f"<@666378959184855042> someone posted to the blog, you should probably approve it {responce.status_code}") + async def on_error(self, error: nextcord.DiscordException, interaction: nextcord.Interaction): + error = traceback.format_exc() + print(error, file=sys.stderr) + message = f"```py\n{error[-1800:]}\n```\n Contact the bot owner if the error persists" + try: + await interaction.send(message, ephemeral=True) + except: + try: + await interaction.followup.send(message, ephemeral=True) + except: + await interaction.response.send_message(message, ephemeral=True) + + class wordpress(commands.Cog): def __init__(self, bot: commands.Bot):