So ändern Sie die vom Discord-Bot gesendete Antwort mit einer SchaltflächePython

Python-Programme
Guest
 So ändern Sie die vom Discord-Bot gesendete Antwort mit einer Schaltfläche

Post by Guest »

Mit discord.py erstelle ich einen Bot, der einem Befehl folgt und eine Folge von Antworten mit einem Auswahlmenü sendet. Basierend auf der im Menü getroffenen Auswahl werden der in der Antwort angezeigte Text und das Auswahlmenü aktualisiert. Nach 8 Auswahlmenüs ändere ich die Antwort erneut mit neuem Text und einer Schaltfläche „Weiter“. Dann sende ich eine Nachricht im Kanal. Wenn der Benutzer auf die Schaltfläche „Weiter“ klickt, sollte er die Antwort erneut ändern, aber in diesem Schritt schlägt dies fehl – ​​die Antwort wird nicht aktualisiert und zeigt „Interaktion fehlgeschlagen“ an.

Code: Select all

async def cmd_choixpeau(interaction : discord.Interaction) :
class bouton_choixpeau_suivant(discord.ui.View) :
@discord.ui.button(label="C'est partis", style=discord.ButtonStyle.blurple)
async def suivant_callback(self, interaction : discord.Interaction, button) :
await questionnaire_choixpeau(interaction, Q1, id)

await interaction.response.send_message(embed = embed_choixpeau, view = bouton_choixpeau_suivant(), ephemeral = True)

Code: Select all

async def questionnaire_choixpeau(interaction : discord.Interaction, numQ : dict, id : int) :
class select_questionnaire(discord.ui.View):
@discord.ui.select( ... )
async def select_callback(self, ctx : discord.Interaction, select) :
if numQ == Q1 :
await questionnaire_choixpeau(ctx, Q2, id)
elif numQ == Q2 :
await questionnaire_choixpeau(ctx, Q3, id)
elif numQ == Q3 :
await questionnaire_choixpeau(ctx, Q4, id)
elif numQ == Q4 :
await questionnaire_choixpeau(ctx, Q5, id)
elif numQ == Q5 :
await questionnaire_choixpeau(ctx, Q6, id)
elif numQ == Q6 :
await questionnaire_choixpeau(ctx, Q7, id)
elif numQ == Q7 :
await questionnaire_choixpeau(ctx, Q8, id)
elif numQ == Q8 :
await attribution_maison(ctx, id)

await interaction.response.edit_message(embed = embed, attachments = [], view = select_questionnaire())

Code: Select all

async def attribution_maison(interaction : discord.Interaction, id : int) :
. . .
await annonce_maison(interaction, id, max_key[0])

Code: Select all

async def annonce_maison(interaction : discord.Interaction, id : int, maison : str) :
class bouton_tuto_suivant(discord.ui.View) :
def __init__(self, maison):
super().__init__()  # Appel au constructeur parent pour initialiser la vue
self.maison = maison

@discord.ui.button(label="Continuer", style=discord.ButtonStyle.blurple)
async def suivant_callback(self, ctx : discord.Interaction, button) :

if maison == "Gryffondor" :
bienvenue_gryffondor = discord.Embed(...)
await ctx.response.edit_message(embed = bienvenue_gryffondor, view = None)
...
embed = discord.Embed(...)
await interaction.response.edit_message(embed = embed, view = bouton_tuto_suivant(maison))
Ich habe versucht, die Reihenfolge des Sendens der Nachricht und des Aktualisierens der Antwort zu ändern sowie die Interaktion über die Funktion und die über die Schaltfläche zu verwenden, aber es hat nicht funktioniert.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post