S
S
sagittelnerd2021-08-18 17:35:15
Python
sagittelnerd, 2021-08-18 17:35:15

How to expand a possible telegram bot written in python (Varieties of answers)?

How to supplement this telegram bot so that when you enter certain phrases, a certain phrase is taken from the config folder. (Circled within the code, but with different data, both input and output).

@bot.message_handler(content_types=["text"])
def get_phrase(message):
    if message.text == "Я не красивая":
        bot.send_message(message.chat.id, random.choice(config.phrases))
    else:
        bot.send_message(message.chat.id, "Ятт")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RusiDev, 2021-08-19
@RusiDev

Use the random library

import random as r

otvet = ["ты не тупой", "ты умный", "красавчик"] // значения
s_otvet = r.choice(start_words) // выбирает рандомно слова

@bot.message_handler(content_types=["text"])
def get_phrase(message):
    if message.text == "Я не красивая":
        bot.send_message(message.chat.id, s_otvet)
    else:
        bot.send_message(message.chat.id, "Ятт")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question