我正在尝试从我的 python 代码的其他部分开始和停止一个 while 循环,但它运行不正常。
我正在使用 pyTelegramBotAPI 向我的机器人发布一些帖子,但它似乎不起作用:
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)