How would one make a command case-insensitive without adding many aliases for different capitalizations like this:
@bot.command(pass_context = True, name = 'test', aliases=['Test', 'tEst', 'teSt', 'tesT', 'TEst', 'TeSt', 'TesT', 'tESt', 'tEsT'])
async def test(self, ctx):
#do stuff
Simply convert the message content to lowercase, then compare it against lowercase commands. This way no matter how the input was capitalized the bot sees the same result of "hello".
According to the maintainer, Discord has told that the bots will continue to work fine even after April 2022.
discord.py is a modern, easy to use, feature-rich, and async ready API wrapper for Discord. Features: Modern Pythonic API using async / await syntax.
discord.py does not support slash commands and will never add support for slash commands (as it has shut down) thus I recommend disnake (a popular fork).
On the rewrite branch, commands.Bot
accepts a case_insensitive
parameter
bot = commands.Bot(command_prefix='!', case_insensitive=True)
Note that there is a performance loss when using this feature.
I found a weird way of doing this when making my first discord bot not knowing of the "case_insensitive" property. I instead used this in my "on_message" function.
await bot.process_commands(msg.content.lower())
You can use commands.process_commands()
instead since you are in a Cog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With