Хочу проверять подписан ли пользователь на канал при написании им каждого сообщения. У меня получается такой код, но и он не работает. Как проверять это с помощью декоратора и можно ли это впринципе проверять это в каждом сообщении без костылей?
@client.message_handler(commands = ['start'])
def hello(message):
@check_decorator(message)
def _hello_(message) -> None:
with sqlite3.connect("users.db") as con:
cur = con.cursor()
info = cur.execute('SELECT * FROM users WHERE userid=?', (int(message.chat.id), ))
if info.fetchone() is None:
user_info = (int(message.chat.id), message.from_user.first_name, message.from_user.last_name, undefined_status)
cur.execute(f"""INSERT INTO users VALUES(?, ?, ?, ?);""", user_info)
con.commit()
sti = open('static/welcome.webp', 'rb')
client.send_sticker(message.chat.id, sti)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton(register)
markup.add(item1)
client.send_message(message.chat.id, hello_message.format(message.from_user, client.get_me()), parse_mode='html', reply_markup=markup)
def check_decorator(function, message):
def check_subscribe() -> None:
if client.get_chat_member(channel_chat_id, message.chat.id).status in need_status:
function(message)
else:
client.send_message(message.chat.id, subscribe_error_msg)
return check_subscribe
Traceback (most recent call last):
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 62, in run
task(*args, **kwargs)
File "d:/code/github.com/MIKHANGO/rueducationbot/bot.py", line 81, in hello
@check_decorator(message)
TypeError: check_decorator() missing 1 required positional argument: 'message'
"
Traceback (most recent call last):
File "d:/code/github.com/MIKHANGO/rueducationbot/bot.py", line 274, in
client.polling(none_stop = True, interval = 0)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 427, in polling
self.__threaded_polling(none_stop, interval, timeout)
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 451, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 111, in raise_exceptions
six.reraise(self.exc_info[0], self.exc_info[1], self.exc_info[2])
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\six.py", line 703, in reraise
raise value
File "C:\Users\MIKHAN_GO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 62, in run
task(*args, **kwargs)
File "d:/code/github.com/MIKHANGO/rueducationbot/bot.py", line 81, in hello
@check_decorator(message)
TypeError: check_decorator() missing 1 required positional argument: 'message'