我尝试了以下命令:
@client.command
@commands.has_permissions(ban_members=True)
async def unban(ctx, *, member : discord.Member):
banned_users = await ctx.guild.bans()
member_name, member_disc = member.split("#")
for banned_entry in banned_users:
user = banned_entry.user
if(user.name, user.discriminator)==(member_name, member_disc):
await ctx.guild.unban(user)
unbanned = discord.Embed(title="Unban <:ban:756532045299318784>", description=f"**{member}** is unbanned! <a:tick:756202944461930567>", color=discord.Color.green(), timestamp=datetime.datetime.utcnow())
await ctx.send(embed = unbanned)
await ctx.send(f"Couldn't find **{member}** named person. iTs CaSe SeNsItIvE!")
这只是一个简单的代码,用于输入“ Wumpus#0001”之类的名称。 但这给我显示了一个大错误:
Traceback (most recent call last):
File "C:\Users\Fujitsu\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "c:/Users/Fujitsu/Desktop/Yupiter/bot.py", line 40, in on_command_error
raise error
File "C:\Users\Fujitsu\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Fujitsu\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Fujitsu\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
Ignoring exception in on_command_error
Traceback (most recent call last):
File "C:\Users\Fujitsu\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "c:/Users/Fujitsu/Desktop/Yupiter/bot.py", line 40, in on_command_error
raise error
discord.ext.commands.errors.CommandNotFound: Command "unban" is not found
“找不到命令“ unban””。 我该怎么办,有没有办法允许输入ID而不是用户名#discriminator?
答案 0 :(得分:0)
您刚刚犯了一个简单的错误。 @client.command
必须为@client.command()
。