So I've been trying to get disnake buttons to get to work, for a good amount of time, and I am ending up with "This Interaction Failed", and it doesn't even execute the callback function i defined within the derived class of disnake.ui.button
. There are no errors so i cannot debug whats wrong, It would be appreciated if anyone can point out if there are any problems.
Note: qna is a global variable. I've posted the relevant sections below.
class QueryButton(disnake.ui.Button):
def __init__(self, choice: int, user_id: str, label=None, style=disnake.ButtonStyle.primary, custom_id=None):
super().__init__(label=label, style=style, custom_id=custom_id)
self.choice = choice
self.user_id = str(user_id)
async def callback(self, interaction: disnake.MessageInteraction):
queries = qna["users"]["id"][self.user_id]["queries"][-5:]
query_number = str(queries[str(self.choice-1)])
query = qna["queries"]["id"][query_number]
embed = disnake.Embed(title=f"Query for {query['user']}", color=0xff0000)
embed.add_field(name="Question", value=query["question"], inline=False)
embed.add_field(name="Answer", value=query["answer"], inline=False)
await interaction.response.send_message(embed=embed, ephemeral=True)
# list of buttons as components (this is inside a slash command)
buttons = [QueryButton(choice=str(i), user_id=user_id, label=str(i), style=disnake.ButtonStyle.green, custom_id=str(i)) for i in range(1, len(queries)+1)]
await interaction.followup.send(embed=embeds, components=components)
Edit: I've added logging and here is what gets logged when I click a button.
2022-10-25 00:51:17,821:DEBUG:disnake.client: Dispatching event socket_event_type
2022-10-25 00:51:17,822:DEBUG:disnake.client: Dispatching event message_interaction
2022-10-25 00:51:17,822:DEBUG:disnake.client: Dispatching event button_click
2022-10-25 00:51:17,822:DEBUG:disnake.client: Dispatching event interaction
2022-10-25 00:51:28,202:DEBUG:disnake.gateway: Keeping shard ID None websocket alive with sequence 17.
2022-10-25 00:51:28,263:DEBUG:disnake.gateway: For Shard ID None: WebSocket Event: {'t': None, 's': None, 'op': 11, 'd': None}