I want to make a commands showing uptime of the both, for example Online Time: 1h 10m 15s
Asked
Active
Viewed 283 times
1
-
Does this answer your question? [Discord.py Uptime](https://stackoverflow.com/questions/62483161/discord-py-uptime) – Almog-at-Nailo Jul 06 '21 at 06:28
1 Answers
2
You would save the time when the bot is started and then compare it to the time you called the command.
import datetime as dt
# after you initialize bot itself
bot.launch_time = dt.datetime.utcnow()
@bot.command()
async def uptime(ctx):
delta_uptime = dt.datetime.utcnow() - bot.launch_time
hours, remainder = divmod(int(delta_uptime.total_seconds()), 3600)
minutes, seconds = divmod(remainder, 60)
days, hours = divmod(hours, 24)
await ctx.reply(f"Online Time: {days}d, {hours}h, {minutes}m, {seconds}s")

Abdulaziz
- 3,363
- 1
- 7
- 24