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 if role not in interaction.user.roles
] ]
print(added_roles)
for role in added_roles: for role in added_roles:
await interaction.user.add_roles(role) await interaction.user.add_roles(role)
await interaction.response.send_message( await interaction.response.send_message(
ephemeral=True, ephemeral=True,
delete_after=30,
content="Added Roles: " + ", ".join([ role.mention for role in added_roles ]) content="Added Roles: " + ", ".join([ role.mention for role in added_roles ])
) )
@ -29,54 +29,76 @@ class RemoveRoleSelect(Select):
await interaction.response.send_message( await interaction.response.send_message(
ephemeral=True, ephemeral=True,
delete_after=30,
content="Removed Roles: " + ", ".join([ role.mention for role in removed_roles ]) content="Removed Roles: " + ", ".join([ role.mention for role in removed_roles ])
) )
class AddRoleButton(Button): class AddRoleButton(Button):
async def callback(self, interaction: Interaction): async def callback(self, interaction: Interaction):
view=View() 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( view.add_item(
AddRoleSelect( AddRoleSelect(
min_values=0, 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:", placeholder="Select roles to add:",
options = [ options = 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) ]
]
) )
) )
await interaction.response.send_message( await interaction.response.send_message(
ephemeral=True, ephemeral=True,
delete_after=30,
view=view view=view
) )
class RemoveRoleButton(Button): class RemoveRoleButton(Button):
async def callback(self, interaction: Interaction): async def callback(self, interaction: Interaction):
view=View() 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( view.add_item(
RemoveRoleSelect( RemoveRoleSelect(
min_values=0, 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:", placeholder="Select roles to remove:",
options = [ options = 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']
]
) )
) )
await interaction.response.send_message( await interaction.response.send_message(
ephemeral=True, ephemeral=True,
delete_after=30,
view=view view=view
) )