MessageFilter.check_update() телеграммаPython

Программы на Python
Anonymous
MessageFilter.check_update() телеграмма

Сообщение Anonymous »

это код, который я тестирую

Код: Выделить всё

from typing import Final
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
import sys
# function that implements the message handler
TOKEN: Final = '6925586576:AAG73ASaMl2kMRE5JrurKP6rBeKyURZbfG8'
BOT_USERNAME: Final = '@flissi_bot'

# command

async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Hi! I'm pizza_bot . I can help you with your shopping needs.")

async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("Hi! I'm pizza_bot. tape somthing so i can help you.")

async def custom_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("the a custon command.")

# reponses

def handel_responses(text: str) -> str:

processed: str = text.lower()

if 'hello' in processed:
return 'hello'
if 'how are you' in processed:
return 'I am fine, thank you'
if 'goodbye' in processed:
return 'goodbye'
if 'thank you' in processed:
return 'you are welcome'

return 'I do not understand you'

async def handel_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
message_type: str = update.message.chat.type
text: str = update.message.text

print(f'User ({update.message.chat_id})in {message_type}: "{text}"')

if message_type == 'group':
if BOT_USERNAME in text:
new_text: str = text.replace(BOT_USERNAME, '').strip()
response: str = handel_responses(new_text)
else:
return
else:
response: str = handel_responses(text)
print('Bot', response)
await update.message.reply_text(response)

async def error(update: Update, context: ContextTypes.DEFAULT_TYPE):
print(f'Update "{update}" caused error "{context.error}"')

if __name__ == '__main__':
print('starting bot...')
app = Application.builder().token(TOKEN).build()

# commands
app.add_handler(CommandHandler('start', start_command))
app.add_handler(CommandHandler('custom', custom_command))
app.add_handler(CommandHandler('help', help_command))

# Messages
app.add_handler(MessageHandler(filters.Text, handel_message))

# Errors
app.add_error_handler(error)

# Poll the bot
print('polling bot...')
app.run_polling(poll_interval=3)

у меня возникла ошибка: Обновить «Обновить(message=Message(channel_chat_created=False,chat=Chat(first_name='Flissi', id=6143267777, Last_name='Hamed', type=) ), date=datetime.datetime(2024, 5, 10, 2, 22, 59, tzinfo=datetime.timezone.utc), delete_chat_photo=False, from_user=User(first_name='Flissi', id= 6143267777, is_bot=False, Language_code='en', Last_name='Hamed'), group_chat_created=False, message_id=28, supergroup_chat_created=False, text='hello'), update_id=589857240)" вызвало ошибку "MessageFilter.check_update( ) отсутствует 1 обязательный позиционный аргумент: 'update'"
может ли кто-нибудь помочь?

Подробнее здесь: https://stackoverflow.com/questions/784 ... e-telegram

Вернуться в «Python»