@bot.message_handler(commands=['send'])
def send(message):
admins = open('admins.txt', 'r', encoding='utf-8').read().split('\n')
if str(message.chat.id) in admins and len(message.text.split()) >= 2:
cache = ''
for text in message.text.split()[1::]:
cache+=text+' '
a = 0
n = 0
users = open('users.txt', 'r', encoding='utf-8').read().split('\n')
for user in users:
if user != '':
try:
bot.send_message(user, cache)
a+=1
except Exception as e:
users.remove(user)
with open('users.txt', 'w', encoding='utf-8') as f:
for u in users:
f.write(f'{u}\n')
n+=1
bot.send_message(message.chat.id, f'Всего отправлено сообщений: {n}\nУспешно: {a}')