Бот реагирует на команды со всех чатов в которых он есть, telebot
Сделал бота на PyTellegrambotAPI, он ставит реакцию на каждое сообщение, бота можно выключать/включать, но когда я выключаю его в одном чате, он выключается во всех
import telebot
from telebot import types
import time
global pause
pause = True
bot = telebot.TeleBot('...')
CONTENT_TYPES = ["text", "audio", "document", "photo", "sticker", "video", "video_note", "voice", "location", "contact",
"new_chat_members", "left_chat_member", "new_chat_title", "new_chat_photo", "delete_chat_photo",
"group_chat_created", "supergroup_chat_created", "channel_chat_created", "migrate_to_chat_id",
"migrate_from_chat_id", "pinned_message"]
@bot.message_handler(content_types=['text'])
def lol(message):
print(message.text, ' test')
print('lol')
if pause == False and message.text != '/stop':
print('lol if')
bot.set_message_reaction(message.chat.id, message.message_id, [types.ReactionTypeEmoji('?')])
else:
if message.text == '/start':
print('lol else start stop in')
start(message)
return
elif message.text == '/stop':
print('lol else start stop in')
start(message)
return
else:
print('not in')
pass
@bot.message_handler(commands=['start', 'stop'])
def start(message):
print('start')
if message.text == '/start':
global pause
pause = False
print('start if pause false')
print(pause)
elif message.text == '/stop':
pause = True
print('start if pause true')
print(pause)
return
else:
print('start else')
pass
bot.polling(none_stop=True)
Ответы (1 шт):
Автор решения: Денис Буторин
→ Ссылка
В объекте message есть вся информация: из какого чата (канала или личных сообщений) и от какого пользователя пришло сообщение. Надо лишь отсеять ненужные.