6

Сделал простого telegram-бота:

import telebot
@bot.message_handler(content_types=["text"])
def repeat_all_messages(message):
    if (message.text.split(" ")[0].upper() == 'BOT,'):
        bot.send_message(message.chat.id, 'I\'m here')

Все отлично работает, но когда добавляю его в групповой чат, то он молчит. Подскажите, как сделать его адаптированным к групповым чатам ?

1 ответ 1

9

Вариантов несколько:

  1. Можно обращаться к боту через слеш / - /YourMessage, если в группе несколько ботов, то с упоминанием его юзернейма - /YourMessage@YourBotName.
  2. Можно задать боту список команд с помощью @BotFather, тогда при вводе слеша пользователь увидит список всех доступных команд и сможет выбрать нужную.
  3. Можно отключить privacy mode, тогда к бот будет получать все сообщения от группы, кроме сообщений от других ботов. По умолчанию privacy mode включен.
  4. Можно сделать бота администратором группы, что так же позволит получать все сообщения от группы, кроме сообщений от других ботов.

What messages will my bot get?

Your bot will receive all messages from users in one-on-one chats. Privacy mode only applies to messages in groups (or supergroups).

Privacy mode is always disabled if your bot is an admin in the group. For supergroups, privacy mode is set to what your bot was using when it joined the group — if you change it later, you'll need to remove the bot and add it again for changes to take effect. By default, your bot runs in privacy mode and only sees the following messages in groups (or supergroups):

Replies to the bot's own messages (messages sent via a custom keyboard are always a reply to the bot). Commands from users meant for your bot (e.g. /start@YourBot). General commands from users (e.g. /start) if your bot was the last bot that sent a message to the group. Service messages (e.g. when somebody leaves or joins a group, group name or photo changes, etc.). If your bot is an admin or if privacy mode is disabled, your bot will get all messages sent to the group, except for messages from other bots.

Ссылка

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.