Search code examples
pythondiscorddiscord.pybots

Discord.py - Bot unable to kick


I find that I am unable to kick members or other bots using the kick command in my bot. Both I and the bot have administrator permissions. Why could this be happening? I get no compilation errors.

@client.command() ##kick
@has_permissions(kick_members = True) # to check the user itself
async def kick(ctx, member : discord.Member, *, reason=None):
    try:
        await member.kick(reason=reason)
        await ctx.send(+member.mention + " has been sent to the ministry of love for reeducation.")
    except:
        await ctx.send("You cannot!")

EDIT: Thanks for the fixes in the comments below. I also came to the realization that I was trying to kick a user of equal level (deprecated bot) and so that also played a part in it not working. I tried to kick a standard user and it worked great!


Solution

  • Guessing that the message received from the bot is "You cannot!", the exception thrown is a TypeError, and it is handled because you have wrapped it in try/except. To make sure, remove the error handling and check your result.

    The complete error would look like this: TypeError: bad operand type for unary +: 'str'.

    Resources


    Bug

    In line 6, you have added a bad binary operator + in the beginning of argument list, but the operator requires two operands and they are not provided.

    await ctx.send(+member.mention + " has been sent to the ministry of love for reeducation.")
    

    Hence a TypeError is thrown, but it is also handled, so the only result you will see is the "You cannot!" message from the bot.

    Fix

    Simply remove the bad operator, and it should be working fine.

    await ctx.send(member.mention + " has been sent to the ministry of love for reeducation.")