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()
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)
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.