Q
Q
Quaasaar2020-05-14 12:17:19
Python
Quaasaar, 2020-05-14 12:17:19

Discord.py how to run two loops at once?

Here is the code:

from threading import Thread
import discord
from discord.ext import commands

bot = commands.Bot(command_prefix='!')


@bot.command(pass_context=True)
async def f(ctx):
    for i in range(3):
        await ctx.send('Test2')


@bot.command(pass_context=True)
async def f_2(ctx):
    for i in range(3):
        await ctx.send('Test')


th_1, th_2 = Thread(target=f), Thread(target=f_2)


@bot.command(pass_context=True)
async def test1(ctx):
    th_1.start(), th_2.start()
    th_1.join(), th_2.join()

I need the "test1" command to run two cycles 'f' and 'f_2' at once, but it gives an error... How to implement it correctly?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question