Reputation: 119
my bot developed in telebot wont work on group, its suppose to spot a "bad word" and delete the message, but in wont work.
I tried to make it work on private messege and it did
expected: delete messages that contain a word from a list, and reply with a message.
result: do so only in private messages not in group :(
import telebot
import time
bot_token = 'TOKEN'
bot = telebot.TeleBot(token=bot_token)
bw = ['poop']
def has_curse(msgr):
b = False
for i in range(len(bw)):
if bw[i] in msgr:
b = True
break
return b
@bot.message_handler(func = lambda msg: msg.text is not None)
def at_answer(message):
if has_curse(message.text):
bot.reply_to(message,'your message has been deleted')
bot.delete_message(message.chat.id, message.message_id)
while True:
try:
bot.polling()
except Exception:
time.sleep(15)
Upvotes: 2
Views: 1593
Reputation: 888
Bots run by default in privacy mode. As stated in the documentation
A bot running in privacy mode will not receive all messages that people send to the group. Instead, it will only receive:
- Messages that start with a slash ‘/’
- Replies to the bot's own messages
- Service messages (people added or removed from the group, etc.)
- Messages from channels where it's a member
So if your bot is not receiving the update at all, this is the cause.
Since your bot should scan every message sent in the group, the only way to make it work is to turn off privacy mode.
Upvotes: 3