Answer the question
In order to leave comments, you need to log in
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
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
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)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question