Discord.py: Command names that start with numbers.

Created on 9 Jan 2018  路  3Comments  路  Source: Rapptz/discord.py

Hello, quick question:

I've been trying to build a bot of my own creating a basic magic 8 ball command that simply returns a random response, utilizing the code below:

from discord.ext import commands 

class Essentials:
    def __init__(self, bot):
        self.bot = bot

    @commands.command
    async def 8ball(self, message):  #<--- uh oh
        #8ball things

I noticed however that with this system whereby the names of methods in the cogs are used as the command names, you cannot have commands starting with numbers because Python does not allow you to have identifiers beginning with numbers.

I would really like to keep the command as 8ball rather than changing it to something like "eightball." Is there a way to override the default command name and change it to something else?

Thanks in advance!

Most helpful comment

You can pass name="8ball" in the command() constructor, ala

@commands.command(name="8ball")
async def _8ball(self, ...): ...

All 3 comments

You can pass name="8ball" in the command() constructor, ala

@commands.command(name="8ball")
async def _8ball(self, ...): ...

Ah, well that's rather simple then.
Thank you!

Just for future reference, questions like this are far more suited for the help channels in the discord.py help server. The invite can be found inside the README.

Was this page helpful?
0 / 5 - 0 ratings