So basically I was trying to make a cogs loder from a youtube toutorial(https://youtu.be/vQw8cFfZPx0)but i am getting some error and i dont know how to fix it. I am using anaconda navigator virtual environment in vscode. My anaconda navigator virtual environment name is disc This is my file
import discord
import os
from discord.ext import commands
client = commands.Bot(command_prefix= "#")
@client.command()
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}')
@client.command()
async def unload(ctx, extension):
client.unload_extension(f"cogs.{extension}")
@client.command
async def reload(ctx, extension):
client.reload_extension(f"cogs.{extension}")
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
client.run('token')
Here is my cogs file
import discord
from discord.ext import commands
class Example(commands.cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("bot is online")
@commands.command()
async def ping(self, ctx):
await ctx.send("pong")
def setup(client):
client.add_cog(Example(client))
This is my terminal
PS C:\Users\Oindrieel\Desktop\bot> conda activate disc
PS C:\Users\Oindrieel\Desktop\bot> & C:/Users/Oindrieel/anaconda3/envs/disc/python.exe c:/Users/Oindrieel/Desktop/bot/bot.py
Traceback (most recent call last):
File "C:\Users\Oindrieel\anaconda3\envs\disc\lib\site-packages\discord\ext\commands\bot.py", line 606, in _load_from_module_spec
spec.loader.exec_module(lib)
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\Oindrieel\Desktop\bot\bot.py", line 21, in <module>
client.load_extension(f'cogs.{filename[:-3]}')
File "C:\Users\Oindrieel\anaconda3\envs\disc\lib\site-packages\discord\ext\commands\bot.py", line 678, in load_extension
self._load_from_module_spec(spec, name)
File "C:\Users\Oindrieel\anaconda3\envs\disc\lib\site-packages\discord\ext\commands\bot.py", line 609, in _load_from_module_spec
raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.example' raised an error: TypeError: module() takes at most 2 arguments (3 given)
PS C:\Users\Oindrieel\Desktop\bot>
CodePudding user response:
Your code in cogs file is all correct just a simple error. Just change the class Example(commands.cog): to class Example(commands.Cog): where c in Cog is capital. Just change this your code starts to work
