I do not know English, so I am writing to you with google translate. Sorry if I use the wrong word.
What I want to do with this code is to detect the member who left my telegram group and to ban automatically. But I am getting such an error. Can you help me with this? Thanks.
from telegram.ext import MessageHandler, Filters
import telegram
with open("token.txt","r") as f:
TOKEN = f.read()
def start(update,source):
update.message.reply_text("Merhaba")
def handle_left_member(bot, update):
left_user = update.left_chat_member
bot.kickChatMember(chat_id=update.message.chat_id, user_id=left_user.id)
update = telegram.ext.Updater(TOKEN,use_context=True)
disp = update.dispatcher
disp.add_handler(telegram.ext.CommandHandler("start",start))
left_member_handler = MessageHandler(Filters.status_update.left_chat_member, handle_left_member)
disp.add_handler(left_member_handler)
update.start_polling()
update.idle()
The error I encountered is as follows.
No error handlers are registered, logging exception.
Traceback (most recent call last):
File "C:\Users\username\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\ext\dispatcher.py", line 557, in process_update
handler.handle_update(update, self, check, context)
File "C:\Users\username\AppData\Local\Programs\Python\Python311\Lib\site-packages\telegram\ext\handler.py", line 199, in handle_update
return self.callback(update, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\username\Desktop\TelegramBot\den.py", line 11, in handle_left_member
left_user = update.left_chat_member
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CallbackContext' object has no attribute 'left_chat_member'
You have installed a version of python-telegram-bot
between 12.0 and 13.15 but your handle_left_member
function is written for version <=11, as it takes the arguments bot
and update
instead of update
and context
. Please see the transition guide of v12 for details.
Please note that neither of these versions are maintained anymore, only the new version v20.x is mainained. To upgrade your code to v20, please read the release notes and the transition guide .
Disclaimer: I'm currently the maintainer of python-telgeram-bot
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.