问题
I am trying to get the number of how many messages have been sent in a channel, and using the logs_from() function wont work because that only accepts a fixed amount of messages to retrieve, how do I do this?
回答1:
In the discord.py-rewrite branch, there is a TextChannel.history AsyncIterator
. If you pass limit=None
, it will return all the messages from the channel
@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))
You might try passing limit=None
to logs_from
, but it isn't documented as working that way like it is in the rewrite branch.
来源:https://stackoverflow.com/questions/52214425/how-to-get-how-many-messages-has-been-sent-in-a-channel