pycord icon indicating copy to clipboard operation
pycord copied to clipboard

AttributeError: 'Bot' object has no attribute 'all_commands'

Open pratheek78 opened this issue 5 years ago • 5 comments

Summary

Error occurs when using discord.Bot() instead of commands.Bot()

Reproduction Steps

Just replace the commands.Bot() with discord.Bot().

Minimal Reproducible Code

client = discord.Bot(command_prefix = get_prefix, intents = discord.Intents.all(), owner_ids = owners, case_insensitive = True)

Expected Results

Expected result is for the code to run without causing any error, like with commands.Bot()..

Actual Results

this error occurs:

PS C:\Users\prath\Desktop\Python> & "C:/Python Installation/Python39/python.exe" "c:/Users/prath/Desktop/Python/Projects/discord bot/DiscordBot.py" Traceback (most recent call last): File "C:\Python Installation\Python39\lib\site-packages\discord\cog.py", line 668, in _load_from_module_spec setup(self) File "c:\Users\prath\Desktop\Python\Projects\discord bot\cogs\devcommands.py", line 42, in setup client.add_cog(devCommands(client)) File "C:\Python Installation\Python39\lib\site-packages\discord\cog.py", line 550, in add_cog cog = cog._inject(self) File "C:\Python Installation\Python39\lib\site-packages\discord\cog.py", line 458, in _inject raise e File "C:\Python Installation\Python39\lib\site-packages\discord\cog.py", line 452, in _inject bot.add_command(command) AttributeError: 'Bot' object has no attribute 'add_command'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\Users\prath\Desktop\Python\Projects\discord bot\DiscordBot.py", line 56, in client.load_extension(f"cogs.{cog[:-3]}") File "C:\Python Installation\Python39\lib\site-packages\discord\cog.py", line 728, in load_extension self._load_from_module_spec(spec, name) File "C:\Python Installation\Python39\lib\site-packages\discord\cog.py", line 671, in _load_from_module_spec self._remove_module_references(lib.name) File "C:\Python Installation\Python39\lib\site-packages\discord\cog.py", line 617, in _remove_module_references for cmd in self.all_commands.copy().values(): AttributeError: 'Bot' object has no attribute 'all_commands'

Intents

intents = discord.Intents.all()

System Information

  • Python v3.9.6-final
  • py-cord v2.0.0-alpha
    • py-cord pkg_resources: v2.0.0a4148+g2bbf0639
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.22471

Checklist

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

Additional Context

there is also no all_commands, or add_command function in my code. i have checked all my cogs for these as well.

pratheek78 avatar Oct 25 '21 00:10 pratheek78

Any fix?

pratheek78 avatar Oct 25 '21 07:10 pratheek78

discord.Bot() is completely different implementation from commands.Bot() In simple words, discord.Bot() just works like discord.Client with application commands.. If you want to use prefix and all other things, you need to use commands.Bot()

Prince2347X avatar Oct 25 '21 15:10 Prince2347X

what would i do if i wanted to add application commands to my bot which already does a lot of other things, like prefix, etc.?

pratheek78 avatar Oct 25 '21 15:10 pratheek78

Keep the existing code as it as ... You can use commands.Bot too for slash commands.. Like

# assuming this was your previous instance, 
bot = commands.Bot(command_prefix='>', ...)

# AFAIK, you can do this ↓
@bot.slash_command()
async def cmd(ctx):
    ...

Prince2347X avatar Oct 25 '21 16:10 Prince2347X

Thanks for the info. I'll close the issue now

pratheek78 avatar Oct 26 '21 08:10 pratheek78