0

I just finished creating my first bot and it works perfectly in groups and when I message it, however, when I add it to a Channel and give it all permissions it does not work. The echo message function gives an error of caused error 'NoneType' object has no attribute 'text'.

from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from telegram import MessageEntity, InlineQueryResultArticle, InputTextMessageContent

def echo(update, context): # this is from the documentation
    context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)

def error(update, context):
    print(f'Error {update} caused error {context.error}')

def main():
    updater = Updater(API)
    dp = updater.dispatcher
    
    #Echo message
    echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
    dp.add_handler(echo_handler)

    #Handle errors
    dp.add_error_handler(error)

    updater.start_polling()
    updater.idle()

main()
2
  • seems like update.message is being returned as a NoneType , do you give your bot read permission too? Commented Mar 8, 2021 at 11:13
  • Within the channel, under Admin rights, it says the bot "has access to messages". Also "Post messages", "Edit messages of others" and "Delete messages of others" are enabled. So I'm assuming it has read permission or is this enabled elsewhere? Commented Mar 8, 2021 at 11:35

1 Answer 1

0

For channel posts it's update.channel_post not update.message.text. Alternatively, update.effective_message can be used if you don't want to differentiate between channel posts, messages and edited messages/channel posts.

def echo(update, context):
    context.bot.send_message(
    chat_id=update.effective_chat.id, text=update.effective_message)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.