不和谐机器人发送和接收消息时的速度不同

时间:2021-01-16 11:35:59

标签: python discord.py

我有一个发送消息序列的不和谐机器人,我注意到第 5 条和第 6 条消息、第 10 条和第 11 条、第 5n 条和第 5n+1 条消息之间的延迟比其他消息更大,所以我写了一些探索它的代码:

import asyncio
import typing

@bot.command()
async def count_to(ctx, numeral: typing.Optional[int] = 1):
    for i in range(numeral):
        await ctx.send(i)

@bot.command()
async def count_to_2(ctx, numeral: typing.Optional[int] = 1):
    await asyncio.gather(*[ctx.send(i) for i in range(numeral)])

我的直觉是使用 asyncio.gather 会有所帮助,但事实并非如此。我不确定减速带的来源 - 有谁知道是什么导致它以及如何重写 count_to 来解决它?

0 个答案:

没有答案
相关问题