Answer the question
In order to leave comments, you need to log in
I have a bot that sends messages, do I need it to send messages every 30 minutes?
I am making a telegram bot and I need it to send messages every 30 minutes
Here is the code:
import random
import telebot
bot = telebot.TeleBot('Token')
eng_word = ['weather — погода','fine — прекрасный','terrible — ужасный','cold — холодный','hot — жаркий']
@bot.message_handler(commands=['start'])
def welcome(message):
bot.send_message(message.chat.id, "Привет, {0.first_name}!\nЯ -<b>{1.first_name}</b>, бот который поможет выучить английские слова)".format(message.from_user, bot.get_me()),
parse_mode='html')
@bot.message_handler(commands= ['learn'])
def learn(message):
bot.send_message(message.chat.id, random.choice(eng_word))
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
What message?
You need to create a cycle
import asyncio
def learn(message):
while True:
bot.send_message(message.chat.id, random.choice(eng_word))
await asyncio.sleep(1800)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question