#How can I check whether someone responds to my modal or just presses cancel?
1 messages · Page 1 of 1 (latest)
depending on the response from modal, I send an embed with 2 buttons which further completes the whole transaction
Do you want to send a message when they press Cancel too?
yes
the second embed depends upon the value sent in the modal
Can you show the Modal, please?
code or the modal?
Just a screenshot of the UI.
ye it's just a testing bot
trying out new code for the main one
Ah
I'm too lazy to set up multiple bots.
I just block the unstable features for people who aren't Devs haha
lol nice
Hey can I just take a peek at the code? It'll help me with some modals I'm working on. (Don't worry I won't steal your code.)
nor will I steal your idea
I don't really dabble in crypto
literally just copy pasted https://guide.pycord.dev/interactions/ui-components/modal-dialogs/#customization 
Learn how you can implement Modals in your Discord Bot with Pycord!
one sec
class MyModal(discord.ui.Modal):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.add_item(discord.ui.InputText(label="Receiving Coin/Token (Ticker only)"))
async def callback(self, interaction: discord.Interaction):
if self.children[0].value is None:
print('ok this part works')
await message.channel.send(f'Please enter a valid Coin/Token in the popup. Kindly try again.')
await message.channel.send(f'{tip_prefix} {user} {what_has_been_tipped}')
return
self.children[0].value = (self.children[0].value).upper()
if self.children[0].value is None:
print('ok this part works')
await message.channel.send(f'Please enter a valid Coin/Token in the popup. Kindly try again.')
await message.channel.send(f'{tip_prefix} {user} {what_has_been_tipped}')
return
this part was an attempt to see if someone presses cancel
I wonder if you can use on_timeout() to build what you need. 
Then, in there, check if the field is empty or not.
If empty, assume they pressed Cancel.
thonkus
C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ui\modal.py:103: RuntimeWarning: coroutine 'on_message.<locals>.MyModal.on_timeout' was never awaited
self.loop.create_task(self.on_timeout(), name=f"discord-ui-view-timeout-{self.id}")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

class MyModal(discord.ui.Modal):
_timeout_again_and_again = True
async def on_timeout(self):
global _timeout_again_and_again
if _timeout_again_and_again == False:
return
elif _timeout_again_and_again == True:
await message.channel.send("Swap Cancelled, you took too long to enter an input.")
await message.channel.send(f'{tip_prefix} {user} {what_has_been_tipped}')
return
did this
What do you need that boolean for?
You probably need to send a self.stop() when the timeout happens.
to stop the timeout if the person interacts with the modal
According to docs and if I understand them correctly, this should be enough.
ok
how can I solve this
C:\Users\hp\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\ui\modal.py:103: RuntimeWarning: coroutine 'on_message.<locals>.MyModal.on_timeout' was never awaited
self.loop.create_task(self.on_timeout(), name=f"discord-ui-view-timeout-{self.id}")
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
await interaction.response.send_modal(MyModal(title = "Swap Completion", timeout = 1)) is this ok
Yes, probably.
still getting this error 

you can't check if someone pressed cancel
it's not an event that discord broadcasts, all it does is dismiss the modal
I still think you should build that differently. Forget about the Cancel button, especially if you can't manage to make the timeout work to do something similar.
I think the timeout thing would be my best bet
I tried using the on_timeout function similar to how I did it with buttons, but I'm getting this error
I saw it. I have no idea how to fix it.

ok I got it
the error is in the way I set the timeout
earlier I was using this:
await interaction.response.send_modal(MyModal(title = "Swap Completion", timeout = 30))
the timeout= 30 part is causing the problem
the on_timeout function is fine
How do you know? Without that, the function doesn't even get called.
it doesn't take timeout as a parameter
used timeout for one of my buttons before:
and in this modal, it's treated as a literal
Where are we supposed to set that value then? 
don't know 
quite sure my on_timeout function is fine since it's the same as the timeout function my other two buttons use, which work perfectly
i saw setTimeout somewhere on SO but I think that was js
maybe something similar would help out
and if timeout doesn't work, I could make a variable with the value of 30 and then loop it such that it reduces to 0 in 30s and then I execute the on_timout function
not ideal, but should work
I'm looking at the code for Pycord and Modal has a timeout parameter, although it's not listed in docs.
pls send link
