Search code examples
pythoncommanddiscordselfdiscord.py

How to check a list of all commands from discord


I'm trying to check If some argument is a command from my server

async def test(self, ctx, *, cmd: str):

    if cmd in self.bot.commands:

What should I do? The self.bot.commands get a list of commands objects not the names..


Solution

  • The documentation says that self.bot.commands returns a list of commands. One such command object has a name attribute. So you can create a function to check if the message (name) corresponds with a name of an existing command:

    def command_name_exists(name):
        for command in self.bot.commands:
            if name == command.name:
                return True
        return False