Skip to content

Instantly share code, notes, and snippets.

@AileenLumina
AileenLumina / bot.py
Last active May 2, 2022 17:40
discord.py command error handler
async def on_command_error(self, ctx, error):
# if command has local error handler, return
if hasattr(ctx.command, 'on_error'):
return
# get the original exception
error = getattr(error, 'original', error)
if isinstance(error, commands.CommandNotFound):
return
@AileenLumina
AileenLumina / utils.py
Last active December 31, 2017 02:17
Pausable coroutines
# ...
def pausable(pause, resume_check=None, delay_start=None, delay_resume=None):
def inner_wrapper(coro):
@asyncio.coroutine
def replacement_coro(*args, **kwargs):
for x in coro(*args, **kwargs):
try:
if delay_start is not None:
if asyncio.iscoroutinefunction(delay_start):
@AileenLumina
AileenLumina / asyncswitch_test.py
Last active December 7, 2017 13:05
Testing a way to allow the execution of coroutine methods as synchronous methods
import types
import asyncio
import inspect
import time
class API:
# def __new__(cls,
def self_reference(function):