Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a command case insensitive in discord.py

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      
like image 597
Dextication Avatar asked Jan 05 '18 19:01

Dextication


People also ask

How do I make discord commands not case sensitive?

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".

Is discord.py being discontinued?

According to the maintainer, Discord has told that the bots will continue to work fine even after April 2022.

Is discord.py easy?

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.

Does discord.py support slash commands?

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).


2 Answers

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.

like image 80
Patrick Haugh Avatar answered Sep 21 '22 10:09

Patrick Haugh


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.

like image 35
mytholt Avatar answered Sep 21 '22 10:09

mytholt