Discord.py: Is it possible to set name for Cog

Created on 18 Jun 2017  路  7Comments  路  Source: Rapptz/discord.py

Can it be some method or property, not only class name?
Thanks!

feature request v1.0-alpha

Most helpful comment

I use this line inside the cog's __init__ to change the name displayed in the help command:

type(self).__name__ = 'name here'

Be warned, this solution requires you to use "quotes" if you want to use the help command to list all the commands of a cog with spaces its name, since for all the bot knows that is the name of the cog

All 7 comments

No, it's set by the class name.

I use this line inside the cog's __init__ to change the name displayed in the help command:

type(self).__name__ = 'name here'

Be warned, this solution requires you to use "quotes" if you want to use the help command to list all the commands of a cog with spaces its name, since for all the bot knows that is the name of the cog

Keeping this one as a TODO.

I'm trying to modify my bot's display name. Is this a relevant issue?

No.

But it's client.edit_profile on async and clientuser.edit on rewrite.

I use this line inside the cog's __init__ to change the name displayed in the help command:

type(self).__name__ = 'name here'

I have been using this to "rename" my cogs in the past but today i wanted to implement a __local_check() for one of my cogs and it turns out changing the type(self).__name__ of a cog completely breaks __local_check() and __global_check() (probably some more).
When you have changed the name the checks just don't get applied at all.
Checks you write like this:

def my_check():
    async def predicate(ctx):
        #do checks
        return True/False
    return commands.check(predicate)

and apply with

@my_check()

work just fine - even if you changed the __name__.

Should be fixed in https://github.com/Rapptz/discord.py/commit/caf3d17d4aa3ce45435bb96ea6d99317bfef8618

e.g. class Cog(commands.Cog, name='My Name')

Was this page helpful?
0 / 5 - 0 ratings