1

I want to make a commands showing uptime of the both, for example Online Time: 1h 10m 15s

1 Answers1

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