B
B
botdevel2021-10-14 11:04:39
Bots
botdevel, 2021-10-14 11:04:39

How to make uptime so that the timer goes after the bot script is launched and shows how long the discord py bot has been running?

How to make the bot send the uptime to the chat with the command !uptime?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-10-14
@Vindicar

Making a constantly ticking counter is inefficient and inconvenient.
It's better to just save the current time to a variable when starting the bot.
When you are asked for uptime (i.e. in the !uptime command handler), subtract the value stored in the variable from the current time - you will get the time interval between them. This will be the uptime. It remains only to format it beautifully.
See the datetime module , datetime and timedelta data types for details.

R
Ronald McDonald, 2021-10-14
@Zoominger

Start a timer when the script is launched in a separate thread and add one to the counter every second. Well, output when requested.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question