Monday, 13 December 2021

Checks don't work correctly on my library

Summery:

I own my own Discord.py library called "Fusion.py", and I somehow broke commands.check, I don't know how and I tried several things to try and fix it, but nothing worked. Here's the library's Github Page: https://github.com/Senarc-Studios/Fusion.py Here's the link to the exact function: https://github.com/Senarc-Studios/Fusion.py/blob/master/discord/ext/commands/core.py#L1770. Furthermore, I have uninstalled my library and install enhanced-dpy library just to see if that worked and this check function is copied from edpy, therefore if it worked for them it should work for me, but after installing their library it works on their library, but doesn't work on mine... I've asked a lot of people, and no-one could help me... T-T

Code:

def check(predicate: Check, **command_attrs: Any) -> Callable[[T], T]:
    def decorator(func: Union[Command, CoroFunc]) -> Union[Command, CoroFunc]:
        if isinstance(func, Command):
            func.checks.append(predicate)
            func._update_attrs(**command_attrs)
        else:
            if not hasattr(func, "__commands_checks__"):
                func.__commands_checks__ = []
            if not hasattr(func, "__command_attrs__"):
                func.__command_attrs__ = {}

            func.__commands_checks__.append(predicate)
            func.__command_attrs__.update(command_attrs)

        return func

    if inspect.iscoroutinefunction(predicate):
        decorator.predicate = predicate
    else:

        @functools.wraps(predicate)
        async def wrapper(ctx):
            return predicate(ctx)  # type: ignore

        decorator.predicate = wrapper

    return decorator  # type: ignore

Usage Code:

from discord.ext import commands
from cool_utils import Terminal


Const = {
    "TESTERS": []
}

def is_tester():
    Terminal.display("Testing tester")
    async def predicate(ctx):
        try:
            if ctx.message.author.id in Const.get("TESTERS"):
                Terminal.display("TESTER_DEBUG: User is tester")
                return True

            else:
                Terminal.display("TESTER_DEBBUG: User is not tester")
                return False
        except Exception as error:
            Terminal.error(error)
            return False

    try:
        return commands.check(predicate)
    except Exception as error:
        Terminal.error(error)


bot = commands.Bot("!")

@bot.event
async def on_ready():
    print("Test")

@bot.command()
@is_tester()
async def test(ctx):
    await ctx.send("Test")

bot.run("TOKEN")


from Checks don't work correctly on my library

No comments:

Post a Comment