Python 在我的discord机器人上同时运行两个循环

Python 在我的discord机器人上同时运行两个循环,python,discord.py,bots,python-asyncio,Python,Discord.py,Bots,Python Asyncio,因此,python中的discord bot的任务是在用户发送消息“$start”后立即发送嵌入。在此之后,代码将启动while循环并检查用户是否有反应。同时,我想每秒钟编辑一次机器人的消息,这样我就可以显示某种计时器,向用户显示他们还有多少时间可以做出反应,但我不知道如何实现同时运行的计时器。使用多处理是否有用? 如果有人需要它来回答我的问题,下面是我非常具体的代码:) @client.command() 异步def启动(ctx): 定时器=120 remTime=计时器 种子资本=10000

因此,python中的discord bot的任务是在用户发送消息“$start”后立即发送嵌入。在此之后,代码将启动while循环并检查用户是否有反应。同时,我想每秒钟编辑一次机器人的消息,这样我就可以显示某种计时器,向用户显示他们还有多少时间可以做出反应,但我不知道如何实现同时运行的计时器。使用
多处理
是否有用? 如果有人需要它来回答我的问题,下面是我非常具体的代码:)

@client.command()
异步def启动(ctx):
定时器=120
remTime=计时器
种子资本=10000
sessionEmpty=True
玩家[ctx.author]=种子资本

em=discord.Embed(title=“New Poker Session”,description=“正在等待玩家加入…\n请回复我们可以使用
asyncio.gather
同时运行协同程序

#命令后
从datetime导入datetime,timedelta
end_time=datetime.now()+timedelta(秒=30)#反应30秒
异步def coro():
对于范围(30,0,5)内的i:
wait botMsg.edit(f'剩余时间:{i}')#如果不希望删除旧内容,请发送另一条消息
等待异步睡眠(5)
异步def coro2():

而datetime.now()因此,我的问题是,我试图在两个协程中访问相同的消息。我试图1.等待消息的反应,2.每秒更新消息。但是如果我使用asyncio.gather,我必须创建两个单独的函数。是的,这不是问题,如果在同一范围内定义函数,它们将有访问权限对于所有变量,问题是并发运行它们,这就是asyncio.gatherdoes@Toilettenbrain,成功了吗?你还卡住了吗?
@client.command()
async def start(ctx):
    timer = 120
    remTime = timer
    seedCapital = 10000
    sessionEmpty = True

players[ctx.author] = seedCapital

em = discord.Embed(title = "New Poker Session", description = "Waiting for players to join ...\nreact with We can use 
asyncio.gather
to run coroutines concurrently.

#after command
from datetime import datetime, timedelta

end_time = datetime.now() + timedelta(seconds=30) #30 seconds to react

async def coro():
   for i in range(30, 0, 5):
       await botMsg.edit(f'time remaining: {i}') #send another message if you don't want old content to be erased
       await asyncio.sleep(5)

async def coro2():
   while datetime.now() <= endtime:
      #do stuff

await asyncio.gather(coro(), coro2())