How to use the twitchio.ext.commands.core.Command function in twitchio

To help you get started, we’ve selected a few twitchio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TwitchIO / TwitchIO / twitchio / ext / commands / bot.py View on Github external
def remove_cog(self, cogname: str):
        """Method which removes a cog and adds it's commands and events.

        Parameters
        ------------
        cogname:
            The name of the cog you wish to remove.
        """
        cog = self.cogs.pop(cogname, None)
        if not cog:
            return

        for name, member in inspect.getmembers(cog):
            if isinstance(member, Command):
                self.remove_command(member)
            elif name.startswith('event_'):
                del self.extra_listeners[name]
            elif name in self.extra_listeners:
                del self.extra_listeners[member.__name__]

        try:
            unload = getattr(cog, f'_{cog.__name__}__unload')
        except AttributeError:
            pass
        else:
            unload(self)

        del cog
github TwitchIO / TwitchIO / twitchio / ext / commands / bot.py View on Github external
def add_command(self, command):
        if not isinstance(command, Command):
            raise TypeError('Commands passed my be a subclass of Command.')
        elif command.name in self.commands:
            raise CommandError(f'Failed to load command <{command.name}>, a command with that name already exists')
        elif not inspect.iscoroutinefunction(command._callback):
            raise CommandError(f'Failed to load command <{command.name}>. Commands must be coroutines.')

        self.commands[command.name] = command

        if not command.aliases:
            return

        for alias in command.aliases:
            if alias in self.commands:
                del self.commands[command.name]
                raise CommandError(
                    f'Failed to load command <{command.name}>, a command with that name/alias already exists.')
github TwitchIO / TwitchIO / twitchio / ext / commands / core.py View on Github external
def decorator(func):
        if isinstance(func, Command):
            func._checks.append(predicate)
        elif not hasattr(func, '__checks__'):
            func.__checks__ = [predicate]
        else:
            func.__checks__.append(predicate)
        return func
    return decorator