1
1
1bura2021-10-10 13:28:21
Python
1bura, 2021-10-10 13:28:21

Python, Discord how to call a function without waiting for the end of the same function?

the question is very strange, look at the point:

I have a function

@bot.command()
async def test(ctx):
    for i in range(10):
        await ctx.send(i)
        time.sleep(5)


that is, when a person writes !test, he answers with numbers from 0 to 9 with a frequency of 5 seconds
, but how can I make it so that when a person writes !test, he still writes to him, but if he writes !test the second time, he will write in two threads , which do not depend on each other

such that if I write !test I will answer "0", after 2 seconds I write !test again, I will immediately write "0", after 3 seconds I will be answered "1", and after another 2 seconds "one"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sasha Filinsky, 2021-10-11
@UkaUkaa

import asyncio

@bot.command()
async def test(ctx):
    for i in range(10):
        await ctx.send(i)
        await asyncio.sleep(5)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question