0

I have been moderating a telegram group for some time and I have had no issues using the python-telegram-bot package. I actually love it. However, I can't seem to get a functioning "Welcome Message" for when new users join.

Right now, I have tried structuring the function like I do with my command and message handlers:

def welcome(update,context):
    #name = from_user.username
    #update.message.reply_text("""Welcome blah blah blah to the group!""") 

and then calling it it my main function like so:

dp = updater.dispatcher
dp.add_handler(ChatMemberHandler(welcome, ChatMemberHandler.CHAT_MEMBER))
updater.start_polling(allowed_updates=Update.ALL_TYPES)
updater.idle()

But am getting an error: AttributeError: 'NoneType' object has no attribute 'reply_text'

So I guess the "member joined the group" pop up is not considered a message. But I dont know how to extract that event or which handler to use. Any help would be greatly appreciated! Thank you!

2
  • You're trying to reply to the update.message when there's no message in update. Review the documentation, you're using the wrong parameter. It should be something other than message.
    – thethiny
    Jun 14, 2021 at 22:05
  • @thethiny do you have any idea what it would be? Im sorry this is my first time building a telegram bot. i havent dealt with anything other than a message. thank you!
    – antv2291
    Jun 14, 2021 at 22:15

1 Answer 1

4

As thethiny already pointed out, chatmember updates have no associated message: update.message will be None, while update.chat_member will be an instance of ChatMemberUpdated. Note that Message.reply_text is just a shortcut for Bot.send_message(chat_id=message.chat.id, ...), so as long as you have the chat_id you can just use e.g. context.bot.send_message - and you can get that chat_id from ChatMemberUpdated.chat. In fact, you can still use PTBs shortcuts, e.g. update.effective_chat.send_message.

Please check out the docs of

as well as the chatmemberbot.py example provided by PTB.


Disclaimer: I'm currently the maintainer of python-telegram-bot

2
  • absolutely beautiful explanation! thank you so much!
    – antv2291
    Jun 15, 2021 at 14:51
  • Glad to be of help. If I could solve your problem, please consider marking my answer as accepted answer :)
    – CallMeStag
    Jun 15, 2021 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.