Как удалить/добавить роль всем участникам сервера?
Уважаемые кодеры, пытался написать сам, но увы не получилось, поэтому обращаюсь к вам.
В общем команда выглядит так !clearrole @role (!addrolem@role) соответственно это упоминание роли.
Насколько я понял, сначала надо узнать ID роли по упоминанию, а потом по итератору убрать/добавить ее всем участник сервера.
У меня была то одна ошибка, то бот не находил роль, из-за того, что я еще начинающий в библиотеки discord.py у меня не получилось, поэтому буду благодарен тем, кто напишет правильный и рабочий код.
- Вопрос задан более двух лет назад
- 1673 просмотра
Комментировать
Решения вопроса 1
discord.py имеет «расширение» для команд, с вещью, под названием «конвертеры», используйте их.
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)
How can I delete a message in discord.py after a command was executed by an user?
But when I used the code, as described in the solutions, I only received AttributeError: ‘Bot’ object has no attribute ‘delete_message’.
The discord.py API Reference (https://discordpy.readthedocs.io/en/latest/migrating.html#models-are-stateful / https://discordpy.readthedocs.io/en/latest/api.html?highlight=delete%20message#message) only revealed that some of the code had changed with newer versions. So to speak client.delete_message would change to Message.delete(), if I interpreted it correctly!
After changing the code to what I thought it must be I received: NameError: name ‘Message’ is not defined
This is my code at the very last moment. (I am relatively new to discord.py and only used Python in school)
import discord from discord.ext import commands import random import json client = commands.Bot(command_prefix = '/', case_insensitive=True) @client.command(pass_context=True) async def delcommes(ctx): await ctx.send("This is the response to the users command!") await Message.delete(ctx.message, delay=3)
