Not_GG_Gamer
Not_GG_Gamer

Reputation: 25

How to get how many messages has been sent by a user

How to get how many messages have been sent by a user, I tried doing it myself but it didn't work out for me can anyone help me. This is what I came up with:

@client.command(aliases =["m"])
async def messages(ctx, Discord.user=User):
    counter = 0
    async for message in channel.history():
        if message.author == client.user:
          counter += 1
    await ctx.send(f'{ctx.author.mention} sent {counter} messages.')
    

Upvotes: 1

Views: 300

Answers (1)

Jawad
Jawad

Reputation: 2041

Your user parameter is not valid. = indicates default, what you want to use are type hints which are indicated with a :. This is the correct way to pass your user parameter: user: discord.Member.

@client.command(aliases=["m"])
async def messages(ctx, user: discord.Member):
    channel = ctx.message.channel
    counter = 0
    async for message in channel.history():
        if message.author == user:
            counter += 1
    await ctx.send(f'{ctx.author.mention} sent {counter} messages.')

Upvotes: 1

Related Questions