D
D
dima gordey2020-09-25 12:57:08
Python
dima gordey, 2020-09-25 12:57:08

Python telegram bot - I wanted it to give out a greeting sticker when start was written, but how to fix the error?

import telebot

bot = telebot.TeleBot('1352920423:AAFZ1xL_UfOtfNoJXomQeuZCtsgFnXCky1c')

@bot.message_handler(commands=['start'])
def welcome(message):
sti = open('Python/sticker.webp')
bot.send_sticker(message .chat.id, sti)

bot.send_message(message.chat.id, "Welcome, {0.first_name}!\nI'm {1.first_name}, a bot designed to be a bunny.".format(message.from_user , bot.get_me()),
parse_mode="html")

@bot.message_handler(content_types=['text'])
def lalala(message):
bot.send_message(message.chat.id, message.text)

bot.polling (none_stop=True)

5f6dbee3c389a039717906.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-09-25
@SoreMix

Either run the script from its folder, or learn to use full paths to files

import os

sticker_path = os.path.join(os.getcwd(), 'Python', 'sticker.webp')
sti = open(sticker_path)

M
MrP0zitiv4ik, 2020-09-26
@MrP0zitiv4ik

You don't need to send the sticker file, but you need to send the file_id of the sticker. How to get this id? You can use the @idsticker_bot bot or display the message object on the console.
in JS:

bot.start((ctx) => {
    ctx.reply('Привет');
    ctx.replyWithSticker('CAACAgIAAxkBAAISrV9jK2iLT87OMPNYNR-6FEOWm8qrAAInAwACtXHaBg_03s-gxd3sGwQ');
});

To Python
sti = 'CAACAgIAAxkBAAISrV9jK2iLT87OMPNYNR-6FEOWm8qrAAInAwACtXHaBg_03s-gxd3sGwQ'
bot.send_sticker(message.chat.id, sti)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question