I'm trying to make my bot send a message with buttons to select the role you want according to the button, but I admit having trouble after various attempts, currently I have this type of error :
Traceback (most recent call last):
File "C:\Users\Entys\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ui\view.py", line 425, in _scheduled_task
await item.callback(interaction)
TypeError: 'coroutine' object is not callable
As for my code, I show you the part concerned (I announce that there are parts in French, because I am and the goal is for this purpose)
async def printclass(self, ctx):
async def button_callclassa(interaction):
await interaction.check_classA(ctx)
buttonA = Button(label="Classe A", style=discord.ButtonStyle.primary)
buttonA.callback = button_callclassa(ctx)
view = View(timeout=None)
view.add_item(buttonA)
await ctx.send("**Choisis ta classe :**", view=view)
async def check_classA(self, ctx):
user = discord.Member
roleA = discord.utils.find(lambda r: r.name == 'Classe A', ctx.message.guild.roles)
roleB = discord.utils.find(lambda r: r.name == 'Classe B', ctx.message.guild.roles)
roleC = discord.utils.find(lambda r: r.name == 'Classe C', ctx.message.guild.roles)
if roleA not in user.roles and roleB not in user.roles and roleC not in user.roles:
await ctx.add_roles(user, 'Classe A')
else:
await ctx.remove_roles(user, 'Classe A')
await ctx.remove_roles(user, 'Classe B')
await ctx.remove_roles(user, 'Classe C')
await ctx.add_roles(user, 'Classe A')