内联模式无法在 python 编写的电报机器人中工作
Inline mode fails to work in python-written telegram bot
我是 Python 中 Telegram Bot 编程的新手。
我创建了一个简单的机器人@kawaikx_bot,它有一个 /start 命令,可以回复任何文本输入。
from telegram.ext import *
from datetime import datetime
weekdays = [0, 1, 2, 3, 4]
API_KEY = '********************************'
def start_command(update, context):
name_of_day = datetime.today().weekday()
if name_of_day in weekdays:
reply = f"\U00002712 Its a weekday today"
update.message.reply_text(reply, parse_mode='html')
else:
reply = f"💎 <b>Its holiday</b>."
update.message.reply_text(reply, parse_mode='html')
def handle_message(update, context):
name_of_day = datetime.today().weekday()
if name_of_day in weekdays:
reply = f"\U00002712 Its a weekday today"
update.message.reply_text(reply, parse_mode='html')
else:
reply = f"💎 <b>Its holiday</b>."
update.message.reply_text(reply, parse_mode='html')
def main():
updater = Updater(API_KEY)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', start_command))
dp.add_handler(MessageHandler(Filters.text, handle_message))
updater.start_polling()
updater.idle()
main()
我也启用了内联模式。我正在尝试通过调用 bot 名称和一些文本 @kawaikx_bot hello 从 bot 不是成员的群聊中向该 bot 传递消息。但它无法发送回复。
我期待回复'Its a weekday today'
你能帮我找出我的代码有什么问题吗?
提前致谢
CommandHandler
和 MessageHandler
只捕获包含消息的更新。请看一下 this section of the official API docs as well as this PTB example. You should also look up the relevant classes & methods in the docs of PTB.
免责声明:我目前是 python-telegram-bot
.
的维护者
我是 Python 中 Telegram Bot 编程的新手。 我创建了一个简单的机器人@kawaikx_bot,它有一个 /start 命令,可以回复任何文本输入。
from telegram.ext import *
from datetime import datetime
weekdays = [0, 1, 2, 3, 4]
API_KEY = '********************************'
def start_command(update, context):
name_of_day = datetime.today().weekday()
if name_of_day in weekdays:
reply = f"\U00002712 Its a weekday today"
update.message.reply_text(reply, parse_mode='html')
else:
reply = f"💎 <b>Its holiday</b>."
update.message.reply_text(reply, parse_mode='html')
def handle_message(update, context):
name_of_day = datetime.today().weekday()
if name_of_day in weekdays:
reply = f"\U00002712 Its a weekday today"
update.message.reply_text(reply, parse_mode='html')
else:
reply = f"💎 <b>Its holiday</b>."
update.message.reply_text(reply, parse_mode='html')
def main():
updater = Updater(API_KEY)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', start_command))
dp.add_handler(MessageHandler(Filters.text, handle_message))
updater.start_polling()
updater.idle()
main()
我也启用了内联模式。我正在尝试通过调用 bot 名称和一些文本 @kawaikx_bot hello 从 bot 不是成员的群聊中向该 bot 传递消息。但它无法发送回复。
我期待回复'Its a weekday today'
你能帮我找出我的代码有什么问题吗?
提前致谢
CommandHandler
和 MessageHandler
只捕获包含消息的更新。请看一下 this section of the official API docs as well as this PTB example. You should also look up the relevant classes & methods in the docs of PTB.
免责声明:我目前是 python-telegram-bot
.