Answer the question
In order to leave comments, you need to log in
How to remove/add a role to all server members?
Dear coders , I tried to write it myself, but alas, it did not work out, so I turn to you.
In general, the command looks like this !clearrole @role ([email protected]) respectively, this is a mention of the role.
As far as I understand, you first need to find out the role ID by mention, and then remove / add it to all server members by iterator.
I had one mistake, then the bot did not find the role, due to the fact that I am still a beginner in the discord.py library , I did not succeed, so I will be grateful to those who write the correct and working code.
Answer the question
In order to leave comments, you need to log in
discord.py
has an "extension" for commands, with a thing called "converters", use those.
https://discordpy.readthedocs.io/en/stable/ext/com...
@bot.command()
async def massrole(ctx, role: discord.Role): # discord.Role здесь будет использоваться как конвертер:
# https://discordpy.readthedocs.io/en/stable/ext/commands/api.html#discord.ext.commands.RoleConverter
for member in ctx.guild:
if role not in member.roles:
await member.add_roles(role)
We don't like to read the documentation... We find Message.role_mentions
in the documentation and work with it.
Find the first mentioned role in List[Role] and clear it.
Now we just delete / add the role to people.
PS message.guild.members ... add_roles/remove_roles
PSS Sorry, but I don't know py from the word at all, but I hope it helped :3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question