2

I have a command called repeat, I'd like users to be able to call it via typing $Repeat as well as $repeat just incase they get confused by capitilization. If possible I'd like them to also be able to call it with $rep and $Rep as well.

@bot.command(name='repeat', help='type a sequence of words seperated by spaces and they will be repeated back to you as a sequence of messages')
async def repeat(ctx, *lines):
    print("repeating")
    await asyncio.gather(*[ctx.send(line) for line in lines])

I can't see a way of doing that from the documentation - except creating commands rep, Rep and Repeat that call the same function - but that feels inelegant.

1 Answer 1

1

Assuming this is a discord.ext.commands.Bot instance, you can achieve case insensitive matching by specifying case_insensitive=True when instantiating your bot

from discord.ext import commands

bot = commands.Bot(prefix='$', case_insensitive=True)

The second can be achieved by means of passing the aliases parameter to your command decorator

@bot.command(name='repeat', aliases=['rep'], help='...')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.