Selaa lähdekoodia

Err handling is mostly functional. Just some commands will need to include their own error handling as to not spam my inbox with more traditional errors. Maybe a roxbot error channel would be nice.

tags/v1.4.0
roxie 6 vuotta sitten
vanhempi
commit
9c7706a4ca
2 muutettua tiedostoa jossa 41 lisäystä ja 34 poistoa
  1. +37
    -30
      err_handle.py
  2. +4
    -4
      main.py

+ 37
- 30
err_handle.py Näytä tiedosto

@@ -1,30 +1,29 @@
import traceback
import datetime
import load_config
import discord
from discord.ext import commands


class ErrHandle():
def __init__(self, Bot):
self.bot = Bot
self.dev = True # For debugging
class ErrHandle:
def __init__(self, bot_client):
self.bot = bot_client
self.dev = False # For debugging
self.owner = self.bot.get_user(self.bot.owner_id)
print(self.owner)

async def on_error(self, event, *args, **kwargs):
if self.dev:
traceback.print_exc()
else:
embed = discord.Embed(title=':x: Event Error', colour=0xe74c3c) #Red
embed = discord.Embed(title="Roxbot Error", colour=0xe74c3c) #Red
embed.add_field(name='Event', value=event)
embed.description = '```py\n{}\n```'.format(traceback.format_exc())
embed.timestamp = datetime.datetime.utcnow()
try:
await self.bot.send_message(self.bot.owner_id, embed=embed)
except:
pass

await self.owner.send(embed=embed)

async def on_command_error(self, ctx, error):
self.owner = self.bot.get_user(self.bot.owner_id)
print(self.owner)
err_colour = 0x992d22
if isinstance(error, commands.CommandInvokeError):
if self.dev:
@@ -32,34 +31,42 @@ class ErrHandle():
else:
embed = discord.Embed(title=':x: Command Error', colour=err_colour) #Dark Red
embed.add_field(name='Error', value=str(error))
embed.add_field(name='Server', value=ctx.message.server)
embed.add_field(name='Channel', value=ctx.message.channel)
embed.add_field(name='User', value=ctx.message.author)
embed.add_field(name='Server', value=ctx.guild)
embed.add_field(name='Channel', value=ctx.channel.mention)
embed.add_field(name='User', value=ctx.author)
embed.add_field(name='Message', value=ctx.message.content)
embed.timestamp = datetime.datetime.utcnow()
try:
await self.bot.send_message(await self.bot.get_user_info(load_config.owner), embed=embed)
except:
raise error
await self.owner.send(embed=embed)

else:
if isinstance(error, commands.NoPrivateMessage):
embed = discord.Embed(description="This command cannot be used in private messages.", colour=err_colour)
await ctx.send(embed=embed)
embed = discord.Embed(description="This command cannot be used in private messages.")
elif isinstance(error, commands.DisabledCommand):
embed = discord.Embed(description="This command is disabled.", colour=err_colour)
await ctx.send(embed=embed)
embed = discord.Embed(description="This command is disabled.")
elif isinstance(error, commands.CheckFailure):
embed = discord.Embed(description="You do not have permission to do this. Back off, thot!", colour=err_colour)
await ctx.send(embed=embed)
embed = discord.Embed(description="You do not have permission to do this. Back off, thot!")
elif isinstance(error, commands.MissingRequiredArgument):
embed = discord.Embed(description="This command cannot be used in private messages.", colour=err_colour)
embed = discord.Embed(description="Argument missing.")
elif isinstance(error, commands.BadArgument):
embed = discord.Embed(description="Invalid Argument given. Please check them.", colour=err_colour)
embed = discord.Embed(description="Invalid Argument given. Please check arguments given.")
elif isinstance(error, commands.TooManyArguments):
embed = discord.Embed(description="Too many arguments given.")
elif isinstance(error, commands.CommandNotFound):
embed = discord.Embed(description="That Command doesn't exist.")
elif isinstance(error, commands.BotMissingPermissions):
embed = discord.Embed(description="I am missing the following permissions: {}".format(str(error.missing_perms).strip("[]")))
elif isinstance(error, commands.MissingPermissions):
embed = discord.Embed(description="You are missing the following permissions: {}".format(str(error.missing_perms).strip("[]")))
elif isinstance(error, commands.NotOwner):
embed = discord.Embed(description="You do not have permission to do this. You are not Roxie!")
elif isinstance(error, commands.CommandOnCooldown):
embed = discord.Embed(description="This command is on cooldown, please wait {} seconds before trying again.".format(error.retry_after))
else:
embed = discord.Embed(
description="Placeholder embed. If you see this please message {}.".format(self.bot.get_user(self.bot.owner_id)))
await ctx.send(embed=embed)
description="Placeholder embed. If you see this please message {}.".format(str(self.owner)))
embed.colour = err_colour
await ctx.send(embed=embed, delete_after=10)


def setup(Bot):
Bot.add_cog(ErrHandle(Bot))
def setup(bot_client):
bot_client.add_cog(ErrHandle(bot_client))

+ 4
- 4
main.py Näytä tiedosto

@@ -75,13 +75,13 @@ async def on_message(message):
@bot.command()
async def about(ctx):
"""
Outputs info about RoxBot, showing uptime, what settings where set in prefs.ini and credits.
Outputs info about RoxBot, showing uptime, how to report issues, what settings where set in prefs.ini and credits.
"""
ownername = await bot.get_user_info(load_config.owner)
owner = bot.get_user(load_config.owner)
em = discord.Embed(title="About Roxbot", colour=load_config.embedcolour, description=load_config.__description__)
em.set_thumbnail(url=bot.user.avatar_url)
em.add_field(name="Command Prefix", value=load_config.command_prefix)
em.add_field(name="Owner", value=str(ownername))
em.add_field(name="Owner", value=str(owner))
em.add_field(name="Owner ID", value=load_config.owner)
em.add_field(name="Bot Version", value=load_config.__version__)
em.add_field(name="Author", value=load_config.__author__)
@@ -109,5 +109,5 @@ if __name__ == "__main__":

start_time = time.time()
bot.load_extension("config.settings")
#bot.load_extension("err_handle")
bot.load_extension("err_handle")
bot.run(load_config.token)

Loading…
Peruuta
Tallenna