You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord.py 1.5版本:我的Kick命令无法正常工作求助

Let's figure out why your kick command isn't working—there's a small but critical syntax issue that's breaking everything, plus a couple of tweaks to make it more robust.

First, the Big Fix: Missing Parentheses on the Command Decorator

The most immediate problem is your command decorator: you wrote @client.command instead of @client.command(). The command() is a function that needs to be called (hence the parentheses) to properly register the command with your bot. Without those parentheses, the decorator doesn't activate correctly, so Discord never recognizes your kick command when you run it.

Corrected Kick Command Code

Here's the fixed version of your command:

@client.command()  # Added parentheses here—this is essential!
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason = None):
    await member.kick(reason=reason)
    await ctx.send(f'{member} has been kicked')

Tweaking the Error Handler

Your error handling logic is mostly right, but the function name doesn't need the on_ prefix (that's for global bot events like on_message or on_command_error). Renaming it to something like kick_error keeps things consistent and avoids confusion:

@kick.error
async def kick_error(ctx, error):  # Renamed from on_kick_error
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send('Please specify a user')
    elif isinstance(error, commands.CheckFailure):
        await ctx.send('You do not have permission to do that!')
    else:
        # Optional: Print the full error to your console for debugging
        print(f"Kick command error: {error}")
        await ctx.send('There was an error executing this command')

Quick Post-Fix Checks

Once you update the code, double-check these things to make sure everything works:

  • Your bot has the Kick Members permission enabled in the server's role settings
  • The bot's role is placed above the roles of any users you're trying to kick (Discord won't let bots kick users with higher or equal roles)
  • Test the command by mentioning a user, like !kick @ExampleUser Spamming in general

内容的提问来源于stack exchange,提问作者BigRaffasha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 16:07:49