0

I am new to python and i am making a discord bot last night I did cog and this is happening plz help me

import discord
from discord.ext import commands

class moderation(commands.Cog):
    def __init__(self , client):
        self.client = client

    @commands.command()
    async def hello (self, ctx):
        await ctx.reply('My name is Arson and i dont like anything not even you wth who taught me this')

    @commands.command()
    @commands.has_permissions(ban_members=True)
    async def clear(self, ctx,amount=5):   
        await ctx.channel.purge(limit=amount)


def setup(client):
    client.add_cog(moderation(client))

this error is coming

Traceback (most recent call last):
  File "C:\Users\burst\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\burst\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke        
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\burst\AppData\Local\Programs\Python\Python310\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped        
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ExtensionFailed: Extension 'cogs.moderation' raised an error: 
AttributeError: module 'discord.ext.commands.bot' has no attribute 'command'
2
  • Is that the full traceback of the error? Also, what version of discord.py are you using? Please edit your post to include these details, as this will help others better understand your question and assist you more effectively. Commented Apr 20, 2022 at 0:38
  • Also, when is this error occurring? Is it when you launch the program or when you run a command? Commented Apr 20, 2022 at 1:04

1 Answer 1

1

At the start of your code you should have a line with the following structure:

BotName = commands.Bot(description="Discord Bot", command_prefix="!")

Then, rather than using @commands.command(), use @BotName.command()

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.