0

How to make this code work only on a specific date of the week like Saturday or Sunday, and other times return a custom message: this command is been offline or something similar.

@bot.command(pass_context=True)
async def ping(ctx):
    msg = "Pong {0.author.mention}".format(ctx.message)
    await bot.say(msg)
Tristo
  • 2,328
  • 4
  • 17
  • 28
Demotry
  • 869
  • 4
  • 21
  • 40

1 Answers1

1

You could do something like

from datetime import datetime

@bot.command(pass_context=True)
async def ping(ctx):
  if datetime.now().strftime("%A") == "Saturday":
    await bot.say("This command is offline")
  else:
    msg = "Pong {0.author.mention}".format(ctx.message)
    await bot.say(msg)
Tristo
  • 2,328
  • 4
  • 17
  • 28
  • 1
    Is this saturday which gmt time ? – Demotry Oct 06 '18 at 08:21
  • To convert to different timezones you can `from pytz import timezone` and `now_utc = datetime.now(timezone('UTC'))` or if you want US/Pacific `now_pacific = datetime.now(timezone('US/Pacific'))` or whichever you want from [the list](https://stackoverflow.com/questions/13866926/is-there-a-list-of-pytz-timezones) – Tristo Oct 06 '18 at 08:25