K
K
Killir Vanya2292021-07-23 16:04:01
Python
Killir Vanya229, 2021-07-23 16:04:01

How can I find out how many messages were sent by a member in a day or just for the whole time?

My code is below, it doesn't show correctly:

@bot.command()
async def message_count(ctx, member:discord.Member = None):
    count = 0
    async for i in member.history():
        count += 1
    await ctx.send("Сообщений {}".format(count))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RAINGM, 2021-07-23
@VEYREN

import datetime

channels = {}
d = datetime.datetime.today() - datetime.timedelta(days=1)
for channel in ctx.guild.text_channels:
    if channel.permissions_for(channel.guild.get_member(user_id)).view_channel:
        messages = 0
    async for message in channel.history(limit=100000, after=d):
        messages += 1
    channels[channel.id] = messages

c = 0
top_channels = ""
while c != 5:
    h = max(channels, key=channels.get)
    channel = discord.utils.get(guild.text_channels, id=h)
    top_channels += f"`{c + 1}`. {channel.mention}: {channels[h]}\n"
    channels.pop(h)
    c += 1
yield top_channels

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question