How do I count how often a command was executed?

Dominik

I would like to display via bot how many times a command has been executed. For this I have already inquired here on the platform and have tried different things. About my code:

e = discord.Embed(color=discord.Colour.green())
user = ctx.author
e.title = f "New suggestion!"
e.set_footer(text=f"{user} | {user.id}")
e.description = f "**__Submitter:__**\n {ctx.author}"
e.add_field(name="__Suggestion:__", value=f"{text}")
e.set_thumbnail(url=ctx.message.author.avatar_url)
e.timestamp = datetime.utcnow()
await channel.send(embed=e)
await ctx.message.add_reaction("✅")

The bot should add Suggestion no. #number in the title, which will go up one at a time when the command is executed. I have already tried the following:

    def __init__(self, bot):
        self.bot = bot
        self.counter = 0

#Shortened
e.title = f "Suggestion no. {self.counter}"

Or just as well:

e.title = f "Suggestion no. {self.counter + 1}

But that didn't help, so how do I make sure that a correct number is displayed and that in case of a bot restart this number continues to rise and doesn't start again from the beginning. Note that a global event did not work for me somehow!

Łukasz Kwieciński

You actually need to update the counter variable

self.counter += 1
e.title = f"Suggestion no. {self.counter}"

You can save it in a JSON or text file if you want the variable to continue after the bot restarts

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How often is the GC executed?

How do I get command name of the last executed command?

How can I check how often a replication agent is executed?

How do I get this terminal command to be executed from python?

How do I count how often a column value changes in a pandas dataframe

How do I count how often a column value changes in a pandas dataframe?

SSD: how often should I do fstrim?

How do I detect a command is being executed and then execute an additional command after the current command

How can I count no.of strings executed

How do I count lines and do simple division on the command line?

How often is background fetch executed in iOS?

How to do an if statement from the result of an executed command

I accidentally executed the following command, what did I lose and how do I recover it?

How do I keep command options from breaking other scripts executed within my command?

How do I save the output of last executed command in terminal after normally executing a command?

How do I make canvas_create_oval a button? Where I can click on it and a command will be executed Python

How do i make the movement function for the player count only once so that they can be executed one by one?

How to do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

How do I add '\c' to a psql command executed from a bash script?

How do I fix a button command from being executed as soon as the code is run?

How do I make the message collector only be run by the person who executed the command?

Django: "How often" do I need @transaction.atomic

python sqlite3, how often do I have to commit?

How often do I need to backup my MBR?

How do I prevent the user from clicking a button too often?

How often do I have to ask google to crawl my website?

How do I get the commands executed by Bazel

mocha - how do I list files that will be executed