#how to edit message when button is clicked
1 messages · Page 1 of 1 (latest)
?tag codeblock
Please put your code in a code block:
```py
Here is your Code
```
That makes reading code in Discord a lot easier:
print("This is an example.")
my bad
message is too big to send lmao
done
async def game(ctx):
listofnumbers = ["1","2","3"]
number = random.choice(listofnumbers)
message = await ctx.send("**IT HAS ESCAPED**\n**YOU MUST CATCH IT!**")
await asyncio.sleep(3)
button = Button(style = discord.ButtonStyle.green, emoji = ":arrow_backward:", custom_id = "button1")
button2 = Button(style = discord.ButtonStyle.green, emoji = ":arrow_up_small:", custom_id = "button2")
button3 = Button(style = discord.ButtonStyle.green, emoji = ":arrow_forward:", custom_id = "button3")
view = View()
view.add_item(button)
view.add_item(button2)
view.add_item(button3)
async def button_callback(interaction):
if number != ("1"):
await interaction.response.edit_message("response 1")
else:
await interaction.response.edit_message("response 2")
async def button_callback2(interaction):
if number != ("2"):
await interaction.response.edit_message("response 1")
else:
await interaction.response.edit_message("response 2")
async def button_callback3(interaction):
if number != ("3"):
await interaction.response.edit_message("response 1")
else:
await interaction.response.edit_message("response 2")
button.callback = button_callback
button2.callback = button_callback2
button3.callback = button_callback3
await message.edit(content= f"⠀⠀:watermelon:⠀⠀⠀⠀⠀:watermelon:⠀⠀⠀⠀⠀:watermelon:\n{number}", view=view)
while (((button_callback)) or ((button_callback2)) or ((button_callback3))) != True:
await asyncio.sleep(1)
listofnumbers = ["1","2","3"]
number = random.choice(listofnumbers)
await message.edit(content= f"⠀⠀:watermelon:⠀⠀⠀⠀⠀:watermelon:⠀⠀⠀⠀⠀:watermelon:\n{number}", view=view)
if (((button_callback)) or ((button_callback2)) or ((button_callback3))) == True:
break```
What is the while loop for?
while the button isnt pressed, edit the message every 1 second
And how is a function ever going to be equal to True?
if you pressed the button, i havent used it before and all the guides i read online are unclear
That is not even close to how it works
amazing
Do you know basic Python?
i learnt a decent amount of it before going onto tkinter and then discord
Your solution is incredibly confusing, I'm not sure why that break is there either
Just have a variable that is True to begin with, run the while loop as long as that variable is true and set it to false on your button callbacks
how can i make it so when the button is pressed it edits the message first send instead of sending a whole new one?
The same way you are editing the message in your loop?
yeah apart from it only edits it once
Because your loop never runs, since your if statement is completely wrong
the loop actually does kinda work, it does edit the message every 1 second, but it doesnt stop editing it after its meant to
Yeah, because your check doesn't make any sense at all
This part
It's completely wrong
