'discord.ext.commands.errors.MissingRequiredArgument: extension is a required argument that is missing. | Discord.py error
I am new to Cogs and I was setting up an example cog and when I try to load it shows MissingArguementError
Bot.py
import discord
from discord.ext import commands
import os
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}')
for filename in os.listdir('./cogs'):
if filename.endswith('.py'):
client.load_extension(f'cogs.{filename[:-3]}')
And this is the Cog file => example.py
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 Active')
@commands.command()
async def ping(self, ctx):
await ctx.send('Pong!')
def setup(client):
client.add_cog(Example(client))
And it shows this error when i try to load the cogs
Ignoring exception in command load:
Traceback (most recent call last):
File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 789, in prepare
await self._parse_arguments(ctx)
File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 697, in _parse_arguments
transformed = await self.transform(ctx, param)
File "C:\Users\pc\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 542, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: extension is a required argument that is missing.
Any help is appreciated
Solution 1:[1]
You missed a .
Here's the code:
@client.command()
async def load(ctx, extension):
client.load_extension(f'cogs.{extension}') # You missed a dot (cogs.{extension})
@client.command()
async def unload(ctx, extension):
client.unload_extension(f'cogs.{extension}') # You missed a dot (cogs.{extension})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vinium |
