Role selects now view user specific roles for adding and removing

This commit is contained in:
fanyx 2024-01-23 15:56:01 +01:00
parent d84845b79e
commit a7183a2ee4
1 changed files with 44 additions and 22 deletions

View File

@ -8,12 +8,12 @@ class AddRoleSelect(Select):
if role not in interaction.user.roles
]
print(added_roles)
for role in added_roles:
await interaction.user.add_roles(role)
await interaction.response.send_message(
ephemeral=True,
delete_after=30,
content="Added Roles: " + ", ".join([ role.mention for role in added_roles ])
)
@ -29,54 +29,76 @@ class RemoveRoleSelect(Select):
await interaction.response.send_message(
ephemeral=True,
delete_after=30,
content="Removed Roles: " + ", ".join([ role.mention for role in removed_roles ])
)
class AddRoleButton(Button):
async def callback(self, interaction: Interaction):
view=View()
options = [
SelectOption(
label=f"@{interaction.guild.get_role(role['id']).name}",
value=role['id'],
description=role['description'],
emoji=interaction.client.get_emoji(role['emoji'])
)
for role in interaction.client.config['roles']
if role['id'] not in [ role.id for role in list(interaction.user.roles) ]
]
if options == []:
await interaction.response.send_message(
content="You already own all available roles."
)
return
view.add_item(
AddRoleSelect(
min_values=0,
max_values=len(interaction.client.config['roles']) if len(interaction.client.config['roles']) <= 25 else 25,
max_values=len(options) if len(options) <= 25 else 25,
placeholder="Select roles to add:",
options = [
SelectOption(
label=f"@{interaction.guild.get_role(role['id']).name}",
value=role['id'],
description=role['description'],
emoji=interaction.client.get_emoji(role['emoji'])
)
for role in interaction.client.config['roles']
if role['id'] in [ role.id for role in list(interaction.guild.roles) ]
]
options = options
)
)
await interaction.response.send_message(
ephemeral=True,
delete_after=30,
view=view
)
class RemoveRoleButton(Button):
async def callback(self, interaction: Interaction):
view=View()
options = [
SelectOption(
label=f"@{interaction.guild.get_role(role['id']).name}",
value=role['id'],
description=role['description'],
emoji=interaction.client.get_emoji(role['emoji'])
)
for role in interaction.client.config['roles']
if role['id'] in [ role.id for role in list(interaction.user.roles) ]
]
if options == []:
await interaction.response.send_message(
content="You own none of the available roles."
)
return
view.add_item(
RemoveRoleSelect(
min_values=0,
max_values=len(interaction.client.config['roles']) if len(interaction.client.config['roles']) <= 25 else 25,
max_values=len(options) if len(options) <= 25 else 25,
placeholder="Select roles to remove:",
options = [
SelectOption(
label=f"@{interaction.guild.get_role(role['id']).name}",
value=role['id'],
description=role['description'],
emoji=interaction.client.get_emoji(role['emoji'])
)
for role in interaction.client.config['roles']
]
options = options
)
)
await interaction.response.send_message(
ephemeral=True,
delete_after=30,
view=view
)