【问题标题】:Python discord bot "Command 'ban' is not found" errorPython discord bot“找不到命令'ban'”错误
【发布时间】:2021-04-30 11:02:10
【问题描述】:

我正在尝试制作一个不和谐的机器人,当我尝试禁止成员时,我收到错误“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')

如果有人可以帮助我,我将非常高兴。 谢谢

【问题讨论】:

    标签: python error-handling discord command bots


    【解决方案1】:

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

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

    【讨论】:

    • 我按照你说的做了,但还是不行
    猜你喜欢
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 2019-08-24
    • 2021-02-17
    • 2018-10-21
    • 2021-03-01
    • 2021-11-04
    • 2021-11-19
    相关资源
    最近更新 更多