woohyunjng / discord.py-components

An unofficial third-party library of discord.py for discord components.
https://devkiki7000.gitbook.io/discord-components/
MIT License
128 stars 43 forks source link

The timeout for `wait_for_interaction` doesn't work #31

Closed nouman0103 closed 3 years ago

nouman0103 commented 3 years ago

The title says it all. Seems like it loops through wait_for with that timeout, so each time a non relevant interaction occurs, the timeout kinda resets.

nouman0103 commented 3 years ago

For a temporary fix, I had to modify the client.py to count the time taken in while loop:

from time import time
import asyncio
#.....

        #...
        timer = timeout
        t = time()
        while True:
            timer -= time()-t
            if timer <= 1:raise asyncio.TimeoutError()
            res = await self.bot.wait_for("socket_response", check=check, timeout=timer)
            #.....

Edit: It is kinda broken when there are plenty of responses

I had to remove the while loop and make those if statements default check: (Might be a little dumb, but I had no time to make it a separate function in class and pass that as default check)

        #....
        def default_check(res):
            if res["t"] != "INTERACTION_CREATE":
                return False

            if message.id != int(res["d"]["message"]["id"]):
                return False
            return True

        res = await self.bot.wait_for("socket_response", check=default_check, timeout=timeout)
        #....
kiki7000 commented 3 years ago

Fixed on 0.5.0