Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.84k stars 3.76k forks source link

No command attribute. #1528

Closed amb2127 closed 6 years ago

amb2127 commented 6 years ago

AttributeError: '<class 'discord.client.Client'>' object has no attribute 'command' Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x10dcb3dd8> Unclosed client session

Harmon758 commented 6 years ago

This is as intended. discord.Client does not have a command attribute.

What you're probably looking for is discord.ext.commands.Bot, a subclass of discord.Client in the commands extension: https://github.com/Rapptz/discord.py/blob/1863a1c6636f53592519320a173ec9573c090c0b/discord/ext/commands/bot.py#L146 It does have a command attribute (inherited from discord.ext.commands.GroupMixin, which it also subclasses), which can be used as a decorator to add commands: https://github.com/Rapptz/discord.py/blob/1863a1c6636f53592519320a173ec9573c090c0b/discord/ext/commands/core.py#L568-L577 For the rewrite branch, see https://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#bot and https://discordpy.readthedocs.io/en/rewrite/ext/commands/api.html#discord.ext.commands.GroupMixin.

Any reference to a "command" is likely a part of the commands extension. Assuming you're trying to use the command attribute as a decorator to add a command, you need to use a Bot object instead of a Client object. As an example, see basic_bot.py in the examples folder.

For further help and questions regarding usage of the library, you should join either the official discord.py server or the Discord API server, as the README recommends. Also, in the future, when requesting help with an error, you need to include the full traceback, not just the exception type and message, as well as any relevant code, so that anyone trying to help you can understand what you're trying to do and what's causing the error.