Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention that a Help Command has to be added to a bot before adding it to the Cog #5154

Closed
PythonCoderAS opened this issue Jul 23, 2020 · 4 comments
Assignees
Labels
bug This is a bug with the library.

Comments

@PythonCoderAS
Copy link
Contributor

The Problem

In my extension setup code, I tried to add my help command to my Help cog and then add it to the bot. However, it expects a private variable to be present. Upon further inspection, it seems that this private variable is filled when the help command is added to the bot.

The Ideal Solution

The ideal solution is to make a note in HelpCommand.cog that it needs to be added to the bot before adding a Cog.

@Vexs
Copy link
Contributor

Vexs commented Jul 23, 2020

This would be far more actionable with the related code- I have no idea what you're doing that should result in this.

@Rapptz
Copy link
Owner

Rapptz commented Jul 23, 2020

This issue is a bit too vague to be actionable and almost looks like a bug report disguised as a feature request. There is no traceback nor any mention of what's going on short of guessing. Please give more information if you want something to be done.

@Rapptz Rapptz added the needs info This issue needs more information to be actionable. label Jul 24, 2020
@PythonCoderAS
Copy link
Contributor Author

PythonCoderAS commented Mar 28, 2021

I decided to revisit this issue. This code sample helps.

from discord.ext.commands import Cog, HelpCommand, Bot

class CustomHelpCommand(HelpCommand):
    pass

class CustomCog(Cog):
    pass

chc = CustomHelpCommand()
cc = CustomCog()
>>> chc.cog
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/User/.local/share/virtualenvs/PokestarBot-8lQ-e5KE/lib/python3.8/site-packages/discord/ext/commands/help.py", line 471, in cog
    return self._command_impl.cog
AttributeError: 'NoneType' object has no attribute 'cog'
>>> chc.cog = cc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/User/.local/share/virtualenvs/PokestarBot-8lQ-e5KE/lib/python3.8/site-packages/discord/ext/commands/help.py", line 476, in cog
    self._command_impl._eject_cog()
AttributeError: 'NoneType' object has no attribute '_eject_cog'

Only when you set the HelpCommand to a bot does it create the _command_impl attribute.

>>> Bot("/").help_command = chc
>>> chc.cog
>>> chc.cog = cc
>>> chc.cog
<__main__.CustomCog object at 0x1124de730>

@Rapptz
Copy link
Owner

Rapptz commented Mar 28, 2021

Thanks. That helps.

@Rapptz Rapptz added bug This is a bug with the library. and removed needs info This issue needs more information to be actionable. labels Mar 28, 2021
@Rapptz Rapptz self-assigned this Mar 28, 2021
@Rapptz Rapptz closed this as completed in c4c2cbf Mar 28, 2021
yagomichalak pushed a commit to yagomichalak/discord.py that referenced this issue May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug with the library.
Projects
None yet
Development

No branches or pull requests

3 participants