Home > other >  AttributeError: module 'discord.ext.commands.bot' has no attribute 'command'
AttributeError: module 'discord.ext.commands.bot' has no attribute 'command'

Time:04-20

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'

CodePudding user response:

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()

  • Related