Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot load extensions/cogs in Discord.py anymore on version

Code (most of it is hidden):

import discord
from discord import app_commands
from discord.ext import commands

intents = discord.Intents.default()

bot = discord.Client(
    intents=intents,
    description='REDACTED',
    case_insensitive=True,
    owner_id=REDACTED
)

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name} - {bot.user.id}')

bot.load_extension(cogs.Mod)
bot.run("token")

Error:

Traceback (most recent call last):
  File "C:\Users\Personal\discord-bots\quantum.py\quantum.py", line 18, in <module>
    bot.load_extension(cogs.Mod)
    ^^^^^^^^^^^^^^^^^^
AttributeError: 'Client' object has no attribute 'load_extension'

I was trying to be able to use the <bot/client>.load_<extension/cog>() prompt, but it didn’t work all of a sudden.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

On the current version of discord.py (2.1.0), you can only call load_extension on a discord.ext.commands.Bot (see https://discordpy.readthedocs.io/en/stable/ext/commands/api.html?highlight=load_extension#discord.ext.commands.Bot.load_extension)

As per the API documentation:

This class is a subclass of discord.Client and as a result anything that you can do with a discord.Client you can do with this bot.

So you shouldn’t have any trouble replacing discord.Client with a commands.Bot in your existing code.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading