Z
Z
Zhenia Bel2020-10-25 13:54:54
Automation
Zhenia Bel, 2020-10-25 13:54:54

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

2 answer(s)
Y
youngtitanium, 2020-10-25
@youngtitanium

What message?

Here's some more advice for you:
Не используй телебот, лучше аиограм (aiogram) или птб (python-telegram-bot)

M
Mikhail Demidov, 2020-10-25
@Supchik09

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 question

Ask a Question

731 491 924 answers to any question