Answer the question
In order to leave comments, you need to log in
Telegram bot how to ban a user online?
It is not possible to make a ban for a user inline. I use such a ban system - add user id to mysql ban table Before responding to user action, it checks against the table whether its id is in the ban. For normal buttons or data entry requests, everything works fine. You added a user to the table, and he immediately gets the message "You are banned" for any action. But it doesn't work with inline. I set up the ban myself, but if the banned user does not restart the bot or press the usual buttons, but only continues to use inline, then the inline ban will not pop up.
banam = []
@bot.message_handler(commands = ['start'])
def first(message):
p = ('SELECT user_id FROM blockuser')
cursor.execute(p)
for p in cursor:
banam.append(p[0])
ban = list(set(banam))
if int(message.chat.id) in ban:
bot.send_message(message.chat.id, "Вы забанены")
#Сам инлайн
@bot.callback_query_handler(func=lambda c: True)
def inlin(c):
ban = list(set(banam))
try:
if c.data == 'nazad':
if c.message.chat.id in ban:
bot.send_message(c.message.chat.id, 'BAN')
else:
bot.edit_message_media(media=types.InputMedia(type='photo', media=const.PHOTOINLINE1),
chat_id=c.message.chat.id, message_id=c.message.message_id, reply_markup=inline2())
def inline2():
knopk2 = types.InlineKeyboardMarkup()
but_1 = types.InlineKeyboardButton(text='Картинка 1', callback_data='kar11')
but_2 = types.InlineKeyboardButton(text='Картинка 2', callback_data='kar2')
but_3 = types.InlineKeyboardButton(text='Назад', callback_data='nazad')
but_4 = types.InlineKeyboardButton(text='Выбор', callback_data='vybor')
knopk2.add(but_1)
knopk2.add(but_2)
knopk2.add(but_3)
knopk2.add(but_4)
return knopk2
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question