import telebot
import random
from telebot import types
from PIL import Image
sl= {
    '1': 'E: \ telegrambot \ 1.jpg',
    '2': 'E: \ telegrambot \ 2.jpg',
    '3': 'E: \ telegrambot \ 3.jpg',
    '4': 'E: \ telegrambot \ 4.jpg',
    '5': 'E: \ telegrambot \ 5.jpg',
    '6': 'E: \ telegrambot \ 6.jpg',
    '7': 'E: \ telegrambot \ 7.jpg',
    '8': 'E: \ telegrambot \ 8.jpg',
    '9': 'E: \ telegrambot \ 9.jpg'
sk= {
    '1': 'text1',
    '2': 'text2',
    '3': 'text3',
    '4': 'text4',
    '5': 'text5',
    '6': 'text6',
    '7': 'text7',
    '8': 'text8',
    '9': 'text9'
bot= telebot.TeleBot ('TOKEN');
def ds (message):
    markup= types.InlineKeyboardMarkup ()
    item1= types.InlineKeyboardButton ('Photo', callback_data= 'yes')
    item2= types.InlineKeyboardButton ('Words', callback_data= 'no')
    markup.add (item1, item2)
    bot.send_message (message.chat.id, text= 'Select action:', reply_markup= markup)
@ bot.callback_query_handler (func= lambda call: True)
def callback (call):
    if call.message:
        if call.data== 'yes':
            bot.send_photo (message.chat.id, open (sl [str (random.randint (1,9))])
        elif call.data== 'no':
            bot.edit_message_text (chat_id= call.message.chat.id, message_id= call.message.id, text= sk [str (random.randint (1,9))])
bot.polling (none_stop= True, interval= 0

Add error text by clicking Edit in question

Dmitry2021-12-30 22:06:13

@ user476966 Escape slashes in file paths. And get in the habit of specifying the text of a specific error that the interpreter issues. This is not a forum for psychics. The title of the topic is also completely inappropriate. Such questions are very often simply deleted here. Remember this. At the same time, turnips are negative.

Garry Galler2021-12-30 22:06:13

@Harry Haller, didn't know what the mistake was

user4769662021-12-30 22:06:13

What do you mean did not know? If "knocks out an error", then the error has text. Not able to read or copy?

Эникейщик2021-12-30 22:06:13