N
N
Nikita Avsievich2020-09-21 19:56:55
Python
Nikita Avsievich, 2020-09-21 19:56:55

I'm trying to make the bot in the discord say the exact time on command. Can you help?

In general, after entering the command, I need the bot to write the exact time in Moscow time, since I could not find it on more than one site, I get the feeling that this is not possible)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
youngtitanium, 2020-09-21
@id_wertas

We steal some code from Valery Zhmyshenko imagining that he does not mind:

offset = datetime.timezone(datetime.timedelta(hours=3)
def get_time(offset):
    return datetime.datetime.now(offset)
print(get_time(offset))
#output:
#22:45

V
Valery Zhmyshenko, 2020-09-21
@mcborrrov

import datetime
import telebot

offset = datetime.timezone(datetime.timedelta(hours=3))

print(datetime.datetime.now(offset))


bot = telebot.TeleBot("token")

@bot.message_handler(commands=['start'])
def start(message):
  bot.send_message(message.chat.id, datetime.datetime.now(offset))


if __name__ == '__main__':
  while True:
    try:
      bot.polling(none_stop=True)
    except Exception as e:
      time.sleep(15)

on command, the start will give time according to Moscow time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question