class RoleDropdown(discord.ui.Select):
def __init__(self, roles):
options = [discord.SelectOption(label=role.name, value=str(role.id)) for role in roles if not role.is_bot_managed()]
super().__init__(placeholder="Выберите роль", min_values=1, max_values=1, options=options)
async def callback(self, interaction: discord.Interaction):
role_id = int(self.values[0])
role = interaction.guild.get_role(role_id)
if role:
await interaction.response.send_message(f"Вы выбрали роль: {role.name}", ephemeral=True)
else:
await interaction.response.send_message("Роль не найдена.", ephemeral=True)
class RoleDropdownView(discord.ui.View):
def __init__(self, roles):
super().__init__()
self.add_item(RoleDropdown(roles))
@bot.command()
async def roles(ctx):
roles = ctx.guild.roles[1:] # Исключаем @everyone роль
if roles:
view = RoleDropdownView(roles)
await ctx.send("Вот все роли:", view=view)
else:
await ctx.send("На сервере нет ролей.")