我想实现一个机器人,它使用 pyTelegrambotAPI 在群聊中度过了一个美好的夜晚,但事情不起作用......这是我的代码:
import schedule
import telebot
from threading import Thread
from time import sleep
API_TOKEN = 'HERE MY PRIVATE TOKEN'
bot = telebot.TeleBot(API_TOKEN)
chat_id = 123456789 # CHAT_ID OF THE GROUP (ofc an example)
def schedule_checker():
while True:
schedule.run_pending()
sleep(1)
def wish_good_night():
return bot.send_message(chat_id, "Good night <3")
# Handle '/start'
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, """\
Hi! I'm a simple bot who wishes a good night in a group chat. Don't write me, I cannot
understand you :3\
""")
schedule.every().day.at("23:30").do(wish_good_night)
Thread(target=schedule_checker).start()
bot.polling()
我从 Stack Overflow 上的另一个用户那里获取了这段代码并尝试对其进行编辑,因为它不起作用,但它仍然不起作用。