Role selects now view user specific roles for adding and removing
This commit is contained in:
parent
d84845b79e
commit
a7183a2ee4
46
src/roles.py
46
src/roles.py
|
@ -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,17 +29,14 @@ 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()
|
||||
view.add_item(
|
||||
AddRoleSelect(
|
||||
min_values=0,
|
||||
max_values=len(interaction.client.config['roles']) if len(interaction.client.config['roles']) <= 25 else 25,
|
||||
placeholder="Select roles to add:",
|
||||
|
||||
options = [
|
||||
SelectOption(
|
||||
label=f"@{interaction.guild.get_role(role['id']).name}",
|
||||
|
@ -48,23 +45,33 @@ class AddRoleButton(Button):
|
|||
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) ]
|
||||
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(options) if len(options) <= 25 else 25,
|
||||
placeholder="Select roles to add:",
|
||||
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()
|
||||
view.add_item(
|
||||
RemoveRoleSelect(
|
||||
min_values=0,
|
||||
max_values=len(interaction.client.config['roles']) if len(interaction.client.config['roles']) <= 25 else 25,
|
||||
placeholder="Select roles to remove:",
|
||||
|
||||
options = [
|
||||
SelectOption(
|
||||
label=f"@{interaction.guild.get_role(role['id']).name}",
|
||||
|
@ -73,10 +80,25 @@ class RemoveRoleButton(Button):
|
|||
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(options) if len(options) <= 25 else 25,
|
||||
placeholder="Select roles to remove:",
|
||||
options = options
|
||||
)
|
||||
)
|
||||
await interaction.response.send_message(
|
||||
ephemeral=True,
|
||||
delete_after=30,
|
||||
view=view
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue