Answer the question
In order to leave comments, you need to log in
How to collect the entire signature of the bot, and send them a private message (from the bot)?
I use the Telegraf library - and I can’t even find something in the documentation how to send a private message.
Yes, and a command that would return the list of subscribers. also haven't found it yet.
And what is the best way to implement it?
To push in a DB to which already sent? - if for example the audience of the bot is 3k people. - then it can also be interrupted, not re-send the same?
Or is there an easier way? :)
Answer the question
In order to leave comments, you need to log in
bot.telegram.sendMessage(iduser, `Hi`);
That's just how to find out all users now. that ever communicated with the bot.
if there is no such list of subscribers - or what I don’t remember there, was there a button to subscribe before starting communication with the bot
# -*- coding: utf-8 -*-
import sett
import telebot
import random
import menu
from telebot import types
import time
import traceback
bot = telebot.TeleBot(sett.token)
joinedFile = open('/root/users.txt', 'r')
joinedUser = set()
for line in joinedFile:
joinedUser.add(line.strip())
joinedFile.close()
@bot.message_handler(commands=['start'])
def start(message):
try:
if not str(message.chat.id) in joinedUser:
file = open('/root/users.txt', 'a')
file.write(str(message.chat.id) + '\n')
file.close()
except Exception as e:
print(e)
bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')
@bot.message_handler(commands=['spam'])
def spam(message):
try:
if message.chat.id == sett.admin_id:
for user in joinedUser:
bot.send_message(user, message.text[message.text.find(' '):])
except Exception as e:
print(e)
bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')
@bot.message_handler(commands=['stats'])
def stats(message):
try:
if message.chat.id == sett.admin_id:
joinedFile = open('/root/users.txt', 'r')
bot.send_message(message.chat.id, 'Пользователей: *'+str(len(joinedFile.readlines()))'*, parse_mode='markdown')
joinedFile.close
except Exception as e:
print(e)
bot.send_message(sett.admin_id, 'Произошла ошибка, отправьте кодеру!!!\n'+str(e)+'')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question