how do i add delay onto await()
so say for example i wanted to send a message
would it be await(2) ?? idk
how do i add delay onto await()
so say for example i wanted to send a message
would it be await(2) ?? idk
Welcome to Ask!
Can you please provide a link to your repl so that we can help you easier?
I’m guessing that you need to do a delay. Here’s how
const delay = ms => new Promise(resolve => setTimeout(resolve, ms * 1000));
Usage:
async function myFunction() {
await delay(seconds);
}
Try multiplying seconds
by 1000 (setTimeout
expects values in milliseconds, and there are 1000 milliseconds in every second)
Sorry, forgot to add that. Added ms * 1000
.
raise ConnectionRefusedError("All of your repls are discord self-bots or raiders, and many include slurs and insults. Please delete them.")
Python solution here:
To add a delay on async functions, use
import asyncio
Then in your code where you want delay:
await asyncio.sleep(5) #5 seconds
I thought it was JS, but someone changed the cat to py.
yep, because all their repls are python discord bots
…and all of them are malicious (the oldest one which hasn’t been modified from its template doesn’t count), and we know that OP is still planning to make a sniper so I thought I’d hide the solution until we know they’re using it for something ethical, but
To do a delay, there’s this add on called time. To do the wait, try this.
import time
time.sleep([seconds])
If you don’t want to type time.sleep, and want something else, then you can type this:
from time import sleep as wait
wait([seconds])
If you do not want to use wait, then simply change “wait” to whatever you want from where I say as wait
Example import time
wait.(2)
import time
time.sleep(1) # seconds
If this worked, please mark this post as the solution.
Do note that the time is in seconds. It supports floats too. If you mark a solution, use the one by @OmegaOrbitals. I’m just elaborating on it.
actually @OmegaOrbitals is a bit wrong ;-; use
import asyncio
async def sleep(x: float) -> None:
await asyncio.sleep(x)
asyncio.get_event_loop().run_until_complete(sleep(5)) # if outside of an async func
# otherwise
async def other() -> None:
await sleep(5)
Lemme explain
Basically someone merged How do I add delay onto await() - #12 by zededgacool into this thread but Omega replied to that before it was merged so he didn’t know it was about async
await
stuff.
oh ok neverminda orz ian he made the right descision
Apologies for the confusion. I did merge the topics as it is essentially the same question. Thanks for all your help!
Partly correct, you first need to declare what wait means by saying
from time import sleep as wait
If you do not, it will not know what wait means, because the official command is time.sleep()