fix: avoid clutter from command not found statements (#55)

Also added dependencies
This commit is contained in:
Luis Mayo Valbuena 2024-02-13 22:38:43 +01:00 committed by GitHub
parent 3dc47c8360
commit 4472ca087e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2329 additions and 2 deletions

15
Pipfile Normal file
View File

@ -0,0 +1,15 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
"discord.py" = "==1.7.3"
emoji = "*"
pyyaml = "*"
objection-engine = "*"
[dev-packages]
[requires]
python_version = "3.10"

2295
Pipfile.lock generated Normal file

File diff suppressed because it is too large Load Diff

21
main.py
View File

@ -1,11 +1,10 @@
import discord
import os
import random
import requests
import traceback
import sys
import threading
import time
import json
import yaml
import gc
sys.path.append("./objection_engine")
@ -356,6 +355,24 @@ def renderThread():
except Exception as exception:
print(f"Error: {exception}")
@courtBot.event
async def on_command_error(ctx, error):
# Source: https://gist.github.com/EvieePy/7822af90858ef65012ea500bcecf1612
ignored = (commands.CommandNotFound, )
# Allows us to check for original exceptions raised and sent to CommandInvokeError.
# If nothing is found. We keep the exception passed to on_command_error.
error = getattr(error, 'original', error)
# Anything in ignored will return and prevent anything happening.
if isinstance(error, ignored):
return
# All other Errors not returned come here. And we can just print the default TraceBack.
print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr)
traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
backgroundThread = threading.Thread(target=renderThread, name="RenderThread")
backgroundThread.start()
# Even while threads in python are not concurrent in CPU, the rendering process may use a lot of disk I/O so having two threads