我用python做了一个简单的机器人,它有预定的任务,并在需要时发送消息。我添加了启动机器人的命令并添加了重复的任务。我在私人聊天和我自己的测试群聊中测试了它,它工作正常。但是当我尝试在其他群聊中启动机器人时,它不会读取命令。我将privacy_mode设置为启用,但它不起作用。有趣的是,在我修改消息(添加了一些表情符号)之前,它是有效的,但我不认为它是这样的。下面是代码:
def send_message(context: telegram.ext.CallbackContext):
context.bot.send_message(chat_id=context.job.context, text="Hey, this bot is working")
def callback_timer(update: telegram.Update, context: telegram.ext.CallbackContext):
context.job_queue.run_once(send_message, 1, context=update.message.chat_id)
context.job_queue.run_repeating(send_message, 60*30, context=update.message.chat_id)
def main():
updater = Updater(config.TOKEN, use_context=True)
dp = updater.dispatcher
updater.dispatcher.add_handler(CommandHandler('start_bot', callback_timer, Filters.user(username="@Test_name")))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()发布于 2020-11-19 02:29:08
问题是已经有其他机器人了,而且不知何故我的机器人没有得到命令。我必须使用@my_bot_name来获取命令,如下所示: /print_hello@my_bot_name
https://stackoverflow.com/questions/64837490
复制相似问题