L
L
Loper472019-11-01 13:49:01
Python
Loper47, 2019-11-01 13:49:01

How to find out the number of Telegram bot users in Python?

How to add a button or command (only for the admin), by clicking on which, the bot will send the number of users?

import pyowm
import telebot


owm=pyowm.OWM('df1....51', language = 'ru')

bot = telebot.TeleBot('106...ilQ')

@bot.message_handler(content_types=['text'])
def send_echo(message):
  try:
    observation = owm.weather_at_place(message.text)
    w = observation.get_weather()
    temp=w.get_temperature('celsius')['temp']

    answer = f"В городе {message.text} сейчас {w.get_detailed_status()} \n"
    answer += f"Температура в районе {round(temp)} градусов\n\n"

    if temp<10:
      answer += 'Очень холодно, оденься потеплее))'
    elif temp<17:
      answer += 'Прохладно, лучше оденься:)'
    else:
      answer += 'Не холодно, хоть в трусах иди:)'

    bot.send_message(message.chat.id, answer)
  except pyowm.exceptions.api_response_error.NotFoundError:
      bot.send_message(message.chat.id, 'Город не найден :(')
      

bot.polling(none_stop = True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
robprane, 2019-11-01
@Loper47

Only write user id to the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question