TheSuperRobert
TheSuperRobert

Reputation: 51

My ban command for some reason doesn't work, and I don't know hot to fix it (discord.py)

I made a ban command about a month ago for my bot, and a few days ago, it just stopped working. Does anyone know why? Here is my code:

@client.command()
@commands.has_permissions(ban_members=True)
async def ban(ctx, member : discord.Member, *, reason=None):
    await member.ban(reason=reason)

Here is the error I get:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Context' object has no attribute 'ban'

I need all the help I can get. Thanks in advance!

Upvotes: 1

Views: 84

Answers (1)

ChrisDewa
ChrisDewa

Reputation: 642

you're doing the command in the a Cog. all methods (functions) in a class (in this case, Cog) have their first set as self which is the class itself.

Because you didn't passed "self" "ctx" is being used as it, basically your command is missing one parameter. Try this:

@commands.command()
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, member : discord.Member, *, reason=None):
    await member.ban(reason=reason)

Also, take into consideration that commands.has_permissions works only on the current channel, you probably want to use commands.has_guild_permissions instead

Upvotes: 1

Related Questions