Skip to content

Instantly share code, notes, and snippets.

@AileenLumina
AileenLumina / bot.py
Last active May 2, 2022
discord.py command error handler
View bot.py
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 Dec 31, 2017
Pausable coroutines
View utils.py
# ...
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 Dec 7, 2017
Testing a way to allow the execution of coroutine methods as synchronous methods
View asyncswitch_test.py
import types
import asyncio
import inspect
import time
class API:
# def __new__(cls,
def self_reference(function):