Мне нужно добиться того, чтобы при нажатии кнопки удалялась одна роль и добавлялась другая.
Это мой код:
Код: Выделить всё
class SimpleView(discord.ui.View):
def __init__(self):
self.start_time = None
self.stop_time = None
super().__init__(timeout=None)
@discord.ui.button(label="𝑬𝑵𝑻𝑹𝑨𝑻𝑨⬆️", style=discord.ButtonStyle.green, custom_id="1")
async def entrata(self, interaction: discord.Interaction, button: discord.ui.Button):
orario_it = datetime.now(pytz.timezone('Europe/Rome'))
orario = orario_it.strftime('%H:%M')
allowed_role_id = 1215328270443094128
added_role_id = 1215318583702454352
removed_role_id = 1215328270443094128
allowed_role = discord.utils.get(interaction.guild.roles, id=allowed_role_id)
user = interaction.user
if allowed_role is None or allowed_role not in interaction.user.roles:
await interaction.response.send_message(f"***Per poter entrare in servizio dei essere in: {allowed_role.mention}!***", ephemeral=True)
if allowed_role in interaction.user.roles:
SimpleView.start_time = time.time()
channel = bot.get_channel(1214495527924928522)
embed=discord.Embed(color=0x23a559)
embed.set_thumbnail(url="https://shft.cl/img/c/cdn.discordapp.com-101395680655364460.webp")
embed.add_field(name="⬆️𝑬𝑵𝑻𝑹𝑨𝑻𝑨⬆️", value="", inline=False) #BOTTONE ENTRATA
embed.add_field(name="NOME:", value=f"{interaction.user.mention}", inline=True)
embed.add_field(name="", value="", inline=True)
embed.add_field(name="", value="", inline=False)
embed.add_field(name="", value="", inline=False)
embed.add_field(name="DATA:", value=f"{data}", inline=True)
embed.add_field(name="ORARIO:", value=f"{orario}", inline=True)
embed.set_footer(text="ARMERIA200")
await user.remove_roles(removed_role_id)
await user.add_roles(added_role_id)
await channel.send(embed=embed)
await interaction.response.send_message(f"***SEI ENTRATO IN SERVIZIO ALLE: {orario}.***", ephemeral=True)
It should add and remove a role but it doesn't work, please help me
Источник: https://stackoverflow.com/questions/781 ... a-a-button