AttributeError: 'Bot' object has no attribute 'all_commands'
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
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.
Any fix?
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()
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.?
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):
...
Thanks for the info. I'll close the issue now