如何获取通道中发送的消息数量

问题描述 投票:1回答:1

我试图获取在一个通道中发送了多少消息的数量,并且使用logs_from()函数不会工作,因为它只接受固定数量的消息来检索,我该怎么做?

python-3.x discord discord.py
1个回答
1
投票

分支,有一个TextChannel.history AsyncIterator。如果你传递limit=None,它将返回来自频道的所有消息

@bot.command()
async def message_count(ctx, channel: discord.TextChannel=None):
    channel = channel or ctx.channel
    count = 0
    async for _ in channel.history(limit=None):
        count += 1
    await ctx.send("There were {} messages in {}".format(count, channel.mention))

您可以尝试将limit=None传递给logs_from,但它没有记录为像在重写分支中那样工作。

© www.soinside.com 2019 - 2024. All rights reserved.