Python discord bot“找不到命令'ban'”错误

时间:2021-01-26 16:23:07

标签: python error-handling discord command bots

伙计们我正在尝试制作一个不和谐的机器人,当我尝试禁止成员时,我收到错误“discord.ext.commands.errors.CommandNotFound:找不到命令“ban””

这是我的代码:

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

如果有人能帮助我,我会很高兴。 谢谢

1 个答案:

答案 0 :(得分:0)

您必须将名称传递给 @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')

并且不需要第一个客户端变量,因为您在它之后的行中声明了另一个客户端变量,并且它没有做太多事情。

相关问题