I created a button that, when pressed, adds a role to the user. However, I need to make sure that when pressed again the role is removed. I've tried to do it, but the role is added and immediately removed.
How do I make it so that the role is added and when the same button is pressed again, it is removed?
Code:
@bot.event
async def on_button_click(inter):
res = 'You give role!'
guild = bot.get_guild(inter.guild.id)
if inter.component.id == "button":
role = guild.get_role(IDROLE)
member = inter.author
await member.add_roles(role)
await member.remove_roles(role)
res = 'You remove role!'
await inter.reply(res, ephemeral = True)