2
votes

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

1 Answers

1
votes

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