christopherson
christopherson

Reputation: 423

Keeping track of how many times uses a command in discord.py

I have been trying to figure out how to keep track of how many times a user uses a command. I want to be able to increment and display how many times they have used the command every time they type it. here is some of my code for one command: Ignore Selection Statements

@client.command(pass_context=True)
async def pick(ctx):
    author = ctx.message.author.id
    if 1 <= giftRate <= 2:
        if (1 <= lowFishRange <= 20):
            oneto5 = str(5)
            await client.say("<@%s>" % (author) + " recived " + oneto5 + " 
            fish")

        else:
            oneto5 = str(1)
            await client.say("<@%s>" % (author) + " recived " + oneto5 + " 
            fish")
     else:
        await client.say("<@%s>" % (author) + " seemed to have missed the mark, the only way to gurantee fish is by "
                     "waiting for a cool pant cate to give you some.")

Upvotes: 1

Views: 2205

Answers (1)

hopethatsacleanwet
hopethatsacleanwet

Reputation: 418

You could have a global dictionary to keep track of it. The key would be the user id and the value would be the number of times they've done that particular command. You would need multiple dictionaries, one for each command, or you could have the dict value be a list with each index having the count for a different command.

commandCounts = {}
commandCounts[user.id] = [command1, command2, command3]

Upvotes: 2

Related Questions