我试图从python代码的其他部分开始和停止while循环 而且效果不好。你知道吗
我正在使用pyTelegramBotAPI将一些帖子发布到我的bot,但它似乎不起作用:
RunPosts = True
@bot.message_handler(commands=['do','dontdo'])
def KillOrLive(message: telebot.types.Message):
if message.text == '/do':
RunPosts = True
print('OK')
elif message.text == '/dontdo':
RunPosts = False
while RunPosts == True:
for post in posts:
btn = telebot.types.InlineKeyboardMarkup()
view = telebot.types.InlineKeyboardButton("Get Product", url="t.me/{}".format(post.username))
btn.row(view)
if post.kind == 'photo':
bot.send_photo(admins[0],post.file_id,post.caption,reply_markup=btn)
time.sleep(2)
bot.polling(none_stop=True)
KillOrLive()正在创建名为RunPosts的局部变量,但不更改全局变量。你知道吗
再加一行就行了
下线后:
您可能还需要更改以下代码
至
如果你一遇到帖子就想停下来,那就告诉你停下来
为了更好地调试,请再添加一个打印:
我建议更换:
与
相关问题 更多 >
编程相关推荐