Answer the question
In order to leave comments, you need to log in
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
@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()
Answer the question
In order to leave comments, you need to log in
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:
rolename
rolename = discord.utils.get(ctx.guild.roles)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question