Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

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

question from:https://stackoverflow.com/questions/65905122/python-discord-bot-command-ban-is-not-found-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...