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

'BridgeCommand' object has no attribute 'hidden' when calling "filter_commands()" #1840

Closed
3 tasks done
diminDDL opened this issue Dec 27, 2022 · 1 comment · Fixed by #1867
Closed
3 tasks done

'BridgeCommand' object has no attribute 'hidden' when calling "filter_commands()" #1840

diminDDL opened this issue Dec 27, 2022 · 1 comment · Fixed by #1867
Assignees
Labels
bug Something isn't working priority: medium Medium Priority
Milestone

Comments

@diminDDL
Copy link

diminDDL commented Dec 27, 2022

Summary

I noticed that my custom help command broke recently. Specifically calling filter_commands(mapping[cog]) seems to be the problem here.

Reproduction Steps

  1. Run the code below.
  2. Try to run the !help command.
  3. See it fail.

Minimal Reproducible Code

import discord
from discord.ext import bridge, commands

intents = discord.Intents.default()
intents.message_content = True

bot = bridge.Bot(command_prefix="!", intents=intents)


class TestCog(commands.Cog, name="test cog"):
    def __init__(self, bot):
        self.bot: commands.Bot = bot
    @bridge.bridge_command()
    async def hello(self, ctx):
        """hello"""
        await ctx.respond("Hello!")

class BetterHelpCommand(commands.HelpCommand):
    """
    Custom help command for the bot.
    """
    async def send_embed(self, embed):
        await self.get_destination().send(embed=embed)

    def blank_line(self, embed):
        embed.add_field(name='_ _', value='_ _', inline=False)

    async def send_bot_help(self, mapping):
        e = discord.Embed(title="test")
        e.add_field(name='Contribute at', value="test", inline=False)
        cogs = []
        for cog in mapping.keys():
            n = await self.filter_commands(mapping[cog])
            cogs.append((cog, n))
        cogs = [x for x in cogs if len(x[1]) > 0]
        for i, (cog, cmds) in enumerate(cogs):
            if i % 2 == 0:
                self.blank_line(e)
            h = '\n'.join([cmd.name for cmd in cmds])
            if cog is None:
                e.add_field(name='builtin', value=h, inline=True)
            else:
                e.add_field(name=cog.qualified_name, value=h, inline=True)
        await self.send_embed(e)

bot.help_command = BetterHelpCommand()
bot.add_cog(TestCog(bot))

bot.run("token")

Expected Results

The filter_commands(mapping[cog]) line returns a filtered list of commands.

Actual Results

The following error is generated:

Ignoring exception in command help:
Traceback (most recent call last):
  File "/home/dmytro/.local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 178, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/dmytro/.local/lib/python3.10/site-packages/discord/ext/commands/help.py", line 858, in command_callback
    return await self.send_bot_help(mapping)
  File "/home/dmytro/Documents/projects/minimal bot/./main.py", line 33, in send_bot_help
    n = await self.filter_commands(mapping[cog])
  File "/home/dmytro/.local/lib/python3.10/site-packages/discord/ext/commands/help.py", line 604, in filter_commands
    for cmd in iterator:
  File "/home/dmytro/.local/lib/python3.10/site-packages/discord/ext/commands/help.py", line 584, in <lambda>
    else filter(lambda c: not c.hidden, prefix_commands)
AttributeError: 'BridgeCommand' object has no attribute 'hidden'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/dmytro/.local/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 347, in invoke
    await ctx.command.invoke(ctx)
  File "/home/dmytro/.local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 950, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/dmytro/.local/lib/python3.10/site-packages/discord/ext/commands/core.py", line 187, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'BridgeCommand' object has no attribute 'hidden'

Intents

discord.Intents.default()

System Information

/home/dmytro/.local/lib/python3.10/site-packages/discord/__main__.py:47: DeprecationWarning: VersionInfo.releaselevel is deprecated since version 2.3, consider using release_level instead.
  "- py-cord v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}".format(version_info)
/home/dmytro/.local/lib/python3.10/site-packages/discord/__main__.py:49: DeprecationWarning: VersionInfo.releaselevel is deprecated since version 2.3, consider using release_level instead.
  if version_info.releaselevel != "final":
- Python v3.10.6-final
- py-cord v2.3.2-final
- aiohttp v3.8.3
- system info: Linux 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

@diminDDL diminDDL added the unconfirmed bug A bug report that needs triaging label Dec 27, 2022
@diminDDL
Copy link
Author

Also when trying to call reload_extension() the methods under the bridge_command decorator trigger an error:

  File "/usr/local/lib/python3.10/site-packages/discord/cog.py", line 1118, in reload_extension
    self._remove_module_references(lib.__name__)
  File "/usr/local/lib/python3.10/site-packages/discord/cog.py", line 722, in _remove_module_references
    self.remove_cog(cog_name)
  File "/usr/local/lib/python3.10/site-packages/discord/cog.py", line 706, in remove_cog
    cog._eject(self)
  File "/usr/local/lib/python3.10/site-packages/discord/cog.py", line 592, in _eject
    bot.remove_command(command.name)
AttributeError: 'BridgeCommand' object has no attribute 'name'

@Middledot Middledot added bug Something isn't working and removed unconfirmed bug A bug report that needs triaging labels Jan 11, 2023
@Lulalaby Lulalaby added the priority: medium Medium Priority label Feb 9, 2023
@Lulalaby Lulalaby added this to the v2.5 milestone Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: medium Medium Priority
Projects
None yet
3 participants