[英]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"伙计们,我正在尝试制作 discord 机器人,当我尝试禁止成员时,我收到错误“discord.ext.commands.errors.CommandNotFound:找不到命令“ban””
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()
装饰器。
@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.并且不需要第一个客户端变量,因为您在它之后的行声明另一个客户端变量并且它没有做太多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.