简体   繁体   中英

Python discord bot “Command 'ban' is not found” error

Guys im trying to make a discord bot and when I try to ban a member I get an error "discord.ext.commands.errors.CommandNotFound: Command "ban" is not found"

Here is my code:

import discord
from discord.ext import commands

client = discord.Client

client = commands.Bot(command_prefix = '-')



@client.event
async def on_ready():
  print("Logged in as {0.user} ".format(client))



@client.event
async def on_member_join(member):
  print(f'{member} joined a server')


@client.event
async def on_member_remove(member):
  print(f'{member} left a server')

@commands.command()
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member, *, reason=None):
  await member.ban(reason=reason)
  await ctx.send(f'User {member} has been kick')



client.run('TOKEN')

I would be very happy if anyone can help me. Thanks

You have to pass in a name to the @commands.command() decorator.

@commands.command(name='ban', description='Bans a user')
@commands.has_permissions(ban_members=True)
async def ban(self, ctx, member: discord.Member, *, reason=None):
  await member.ban(reason=reason)
  await ctx.send(f'User {member} has been kick')

And the first client variable isn't needed as you are declaring another client variable the line after it and it doesn't do much.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM