Answer the question
In order to leave comments, you need to log in
QRcode output by TelegramBotAPI image?
I am writing a simple pet project and ran into a problem, qrcode is displayed not as a picture, but as a message, the source code and a screenshot of the result are below
import telebot
from telebot import types
import qrcode
bot = telebot.TeleBot('TOKEN')
@bot.message_handler(commands=['старт'])
def starting_bot(message):
bot.send_message(message.chat.id, 'Привет, я бот, который создаёт QRкоды \n\n/помощь для просмотра умений бота')
@bot.message_handler(commands=['помощь'])
def helping_user(message):
bot.send_message(message.chat.id, 'Чтобы создать QRкод напиши мне /создать')
@bot.message_handler(commands=['создать'])
def creating_qr(message):
bot.send_message(message.chat.id, 'Пришли мне текст, который нужно преобразовать в QRcod')
@bot.message_handler(content_types=['text'])
def creating_qr(message):
for_qr = message.text
img_create_qr = qrcode.make(for_qr)
bot.send_message(message.chat.id, f'Твой QRкод: \n\n{img_create_qr}')
bot.polling(none_stop = True)
@bot.message_handler(commands=['создать'])
def creating_qr(message):
bot.send_message(message.chat.id, 'Пришли мне текст, который нужно преобразовать в QRcod')
@bot.message_handler(content_types=['text'])
def creating_qr(message):
for_qr = message.text
img_create_qr = qrcode.make(for_qr)
img_create_qr.save('qr1.jpg','JPEG')
bot.send_photo('qr1.jpg')
Answer the question
In order to leave comments, you need to log in
You can send without saving
from io import BytesIO
qr_img = qrcode.make('Starting!')
bio = BytesIO()
qr_img.save(bio, 'JPEG')
bio.seek(0)
bot.send_photo(message.chat.id, bio)
Who is interested in the full code of the project, please: (PS the answer to my question was suggested above)
import telebot
from telebot import types
import qrcode
from io import BytesIO
bot = telebot.TeleBot('TOKEN')
@bot.message_handler(commands=['старт'])
def starting_bot(message):
bot.send_message(message.chat.id, 'Привет, я бот, который создаёт QRкоды \n\n/помощь для просмотра умений бота')
@bot.message_handler(commands=['помощь'])
def helping_user(message):
bot.send_message(message.chat.id, 'Чтобы создать QRкод напиши мне /создать')
@bot.message_handler(commands=['создать'])
def creating_qr(message):
bot.send_message(message.chat.id, 'Пришли мне текст, который нужно преобразовать в QRcod')
@bot.message_handler(content_types=['text'])
def creating_qr(message):
qr_img = qrcode.make(message.text)
bio = BytesIO()
qr_img.save(bio, 'JPEG')
bio.seek(0)
bot.send_photo(message.chat.id, bio)
bot.polling(none_stop = True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question