Home > OS >  Why can't my bot kick users despite having admin perms and both intents enabled?
Why can't my bot kick users despite having admin perms and both intents enabled?

Time:10-15

I made a kick command for my discord bot (hosted on repl.it). I enabled all of the intents and the bot has admin privileges, but still it raises an error Code:

intents = discord.Intents.all()
bot = Bot("$",help_command=None,intents=intents)
@bot.command()
async def k(ctx,member:discord.Member):
  await member.kick()

Error as text:

Ignoring exception in command k:
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 91, in k
    await member.kick()
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/member.py", line 568, in kick
    await self.guild.kick(self, reason=reason)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/guild.py", line 1997, in kick
    await self._state.http.kick(user.id, self.id, reason=reason)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 248, in request
    raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/opt/virtualenvs/python3/lib/python3.8/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

the error image1

the error image

i made a totally new bot and made the same kick command

but it still raises an exeption!

CodePudding user response:

Impossible...

...because the Member you tried to kick had an highest role higher than the Bot one.
For example, even if a Bot is an administrator, he can't kick the server owner.


Remember that a discord.Bot object is a way to interact with a discord Bot, which (using the API) can do the same things that a client would manage to do with the same permissions.
Try to kick the same discord.Member that your Bot tried to kick while having the same permissions: you won't be able to do it.


You should check the JSON Error Codes of the Discord API when you don't understand what a Discord.py exception is caused by.

CodePudding user response:

This is because you have not provided a valid reason! Try this:

@bot.command()
async def kick(ctx, member: discord.Member, *, reason=None):
    await member.kick(reason=reason)
    await ctx.send(f'User {member} has kicked.')

Hope it works!

  • Related