【发布时间】:2021-08-15 18:28:57
【问题描述】:
当我点击 MESSAGE 按钮时,我得到了'NoneType' object has no attribute 'chat_id'。
我认为问题是 context=update.message.chat_id (context.job_queue.run_daily - 方法消息)。
另一个问题是我在单击时收到消息,而不是在 12:00(我放入方法 run_daily 的时间)
def start(update:Update, context:CallbackContext) -> int:
options = [[InlineKeyboardButton("MESSAGE", callback_data="DAILY_MESSAGE")]]
optionsMenu = InlineKeyboardMarkup(options)
update.message.reply_text("Welcome", reply_markup=optionsMenu)
return FIRST
def messageText(update, context):
context.bot.send_message(
chat_id=update.callback_query.from_user.id,
text="Message received",
parse_mode=ParseMode.MARKDOWN
)
def message(update, context):
context.job_queue.run_daily(messageText(update, context),
time=time(hour=12, minute=0, second=0, tzinfo=pytz.timezone("Europe/Madrid")),
days=(0, 1, 2, 3, 4, 5, 6),
context=update.message.chat_id)
def main():
updater = Updater("API_KEY", use_context=True)
dp = updater.dispatcher
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
FIRST: [
CallbackQueryHandler(message, pattern='^DAILY_MESSAGE$')
],
},
fallbacks=[CommandHandler('start', start)],
)
dp.add_handler(conv_handler)
updater.start_polling()
updater.idle()
有什么解决办法吗?谢谢
【问题讨论】:
标签: python python-3.x telegram telegram-bot python-telegram-bot