Как решить ошибку "missing 1 required positional argument: 'message''
Не получается сделать бота - постоянно вылазят баги. Либо выдаёт по 2 сообщения, либо ошибку . В создании ботов новичёк, хоть и прошестрил всю документацию по созданию ботов, но комбинация 2-х библиотек как-то не получается.
import telebot
from telebot import types
import schedule
import time
import random
from threading import Thread
bot = telebot.TeleBot("***")
def schedule_checker():
while True:
schedule.run_pending()
time.sleep(1)
@bot.message_handler(content_types=['text'])
def foo(message):
keyboard = types.InlineKeyboardMarkup()
url_button = types.InlineKeyboardButton(text="Перейти на опрос", url="https://docs.google.com/forms/d/e/***")
keyboard.add(url_button)
bot.send_message(message.chat.id, "Привет! Нажми на кнопку и перейди в опрос.",reply_markup=keyboard)
def chat(message):
lines = open("test.txt", encoding="utf8").read().splitlines()
randomline1 = random.choice(lines)
bot.send_message(message.chat.id, text=randomline1)
time.sleep(15)
print(randomline1)
def doo(message):
keyboard = types.InlineKeyboardMarkup()
url_button = types.InlineKeyboardButton(text="Перейти на опрос2",url="https://docs.google.com/forms/d/e/***")
keyboard.add(url_button)
bot.send_message(message.chat.id, "Привет! Нажми на кнопку и перейди в опрос.2",reply_markup=keyboard)
def chat2(message):
lines = open("test.txt", encoding="utf8").read().splitlines()
randomline1 = random.choice(lines)
bot.send_message(message.chat.id, text=randomline1)
time.sleep(15)
print(randomline1)
if __name__ == "__main__":
schedule.every(15).seconds.do(doo)
schedule.every(15).seconds.do(foo)
Thread(target=schedule_checker).start()
scheduler1=schedule.Scheduler()
scheduler2=schedule.Scheduler()
while True:
scheduler1.run_pending()
scheduler2.run_pending()
bot.polling(none_stop=True)
time.sleep(1)
Ответы (1 шт):
Автор решения: Xander
→ Ссылка
Я не особо разбираюсь в telegram, но навскидку кажется, что декоратор @bot.message_handler(content_types=['text']) нужен перед каждой из следующих функций: chat, doo, chat2, а не только перед foo.