Python discord bot“找不到命令'ban'”错误
Posted
技术标签:
【中文标题】Python discord bot“找不到命令\'ban\'”错误【英文标题】: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')
如果有人可以帮助我,我将非常高兴。 谢谢
【问题讨论】:
【参考方案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')
并且不需要第一个客户端变量,因为您在它之后的行声明另一个客户端变量并且它没有太多作用。
【讨论】:
我按照你说的做了,但还是不行以上是关于Python discord bot“找不到命令'ban'”错误的主要内容,如果未能解决你的问题,请参考以下文章
Bash:Python3:找不到命令(Windows,discord.py)