D
D
didrux2020-07-21 18:44:22
Python
didrux, 2020-07-21 18:44:22

How to create condition text equals "/" + "random something" then... Python?

I am using pyTelegramBotAPI
import telebot I have

this code:

@bot.message_handler(content_types=["text"])
def any_msg(message):

if message.text == "/" + "random anything":
bot.send_message(message.from_user. id, "*good*", parse_mode="Markdown")

random_anything is written as an example, I suspect that there must be some function

Question: how to create such a function that if message.text equals "something" + "something -something random", or "something" + "number from 1 to 10"? How is it written in Python?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick, 2020-07-23
@didrux

It's easier to check that if there is some text after /, then it is random (or maybe I misunderstood)
if '/' in message.text and len(message.text) > 1:

A
alex-bul, 2020-07-21
@KOT10

Use the random module https://pythonworld.ru/moduli/modul-random.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question