G
G
German1st2022-02-06 21:53:32
Python
German1st, 2022-02-06 21:53:32

Why doesn't the bot clean up users with a tagged role?

When I enter a command, the bot throws the prescribed message, but does not kick users, and displays this in the console

Ignoring exception in command kickrole:
Traceback (most recent call last):
File "C:\Users\user_German\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\ ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\user_German\Desktop\bot python\discord-bot.py", line 32, in kickrole
await member.kick()
File "C:\Users\user_German\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\member.py", line 568, in kick
await self.guild.kick(self, reason=reason)
File "C:\Users\user_German\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\guild.py", line 1997, in kick
await self._state .http.kick(user.id, self.id, reason=reason)
File "C:\Users\user_German\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\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 "C:\Users\user_German\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\user_German\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\discord\ext\commands\core .py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\user_German\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages \Python37\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


Here is the code itself:
@bot.command(pass_context = True)
@has_permissions(manage_roles=True, ban_members=True, kick_members=True)
async def kickrole(ctx, rolename:discord.Role):
    for member in ctx.guild.members:
        rolename = discord.utils.get(ctx.guild.roles)
    if rolename in member.roles:
        await ctx.send("Почищено")
        await member.kick()


620018742357c563741611.png

PS The bot has administrator rights, its role is higher than the one that needs to be kicked.

The bot also kicks normally, usually with a command to kick a specific participant

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-02-06
@German1st

The code is written incorrectly. For some reason it is taken out for a cycle. The variable is also redefined, although it is a parameter, namely, the role that needs to be excluded. It is generally unclear why it was done and why it is in a cycle. Just conditionally assign the same variable the same 10 times, having received some element from the list of roles? Well, if the block falls out of the loop, the last person is always selected, regardless of his role. And there the role can be higher than the bot, the owner of the server can also be the last person. if rolename in member.roles:rolenamerolename = discord.utils.get(ctx.guild.roles)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question