这是我在我的机器人中使用的踢命令
注意:你需要在写下面的命令之前写这个东西==> from discord.ext.commands import has_permissions, CheckFailure, BadArgument
@bot.command(pass_context=True, name="kick")
@has_permissions(kick_members=True)
async def kick(ctx, *, target: Member):
if target.server_permissions.administrator:
await bot.say("Target is an admin")
else:
try:
await bot.kick(target)
await bot.say("Kicked")
except Exception:
await bot.say("Something went wrong")
@kick.error
async def kick_error(error, ctx):
if isinstance(error, CheckFailure):
await bot.send_message(ctx.message.channel, "You do not have permissions")
elif isinstance(error, BadArgument):
await bot.send_message(ctx.message.channel, "Could not identify target")
else:
raise error
所以现在命令@bot.command(pass_context=True)
@has_permissions(kick_members=True) ==> 它检查是否
使用该命令的用户是否具有该权限。其余部分是不言自明的。
@kick.error 部分检查该 kick 命令的错误。注意:如果在第一部分中你对 async def kick_command
@kick.error 你必须纠正@kick_command.error。
另请注意:
在你的机器人命令中你写了@client=command.Bot(command_prefix='YOUR_PREFIX')
在@bot.command()
您只需将@bot 更改为您在该@client 中编写的内容:
例如。如果你写了@mybot.command_Bot(command_prefix='YOUR_PREFIX')
你必须将@bot 更改为@mybot.command()。如果您有任何问题,请随时提出