Python Telegram Bot - I can’t send photos

Asked

Viewed 164 times

1

I just started programming, so maybe it’s something simple. Anyway, I made a bot on Telegram to simulate a Pokemon hunt. I’m trying to implement that the bot sends a photo of Pokemon when the user finds it, but I can’t.

import logging, random 
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters

pokemon_list = open("pokemon.txt", encoding="utf8") pokemons = [] for line in pokemon_list:
    pokemons.append(line.strip("\n"))

# Enable logging logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)

logger = logging.getLogger(__name__)

# command handlers. def start(update, context):
        update.message.reply_text(
        'Olá {}! Nosso mais novo PokeTrainer!'.format(update.message.from_user.first_name))

def help(update, context):
        update.message.reply_text('Bot desenvolvido para simular um encontro aleatório na grama alta,'
                                  ' utilizando os Pokemons da primeira geração.'
                                  '\n/start - Inicia o bot.'
                                  '\n/help - Ajuda do bot.'
                                  '\n/procurar - Procura um Pokemon na grama alta.'
                                  '\nEncontrou algum erro? Envie um email para: [email protected]')

def procurar(update, context):
        pokemon = random.choice(pokemons)
        update.message.reply_text(f"Você encontrou um {pokemon}!")

def send_photo(update, context):
        bot.sendPhoto(
            chat_id=update.message.chat_id,
            photo='1.png')

# Start the bot. def main():
    updater = Updater("1006417815:AAEE1h8QPug18Gu-d5QAHKC57Vjv_StP2G8", use_context=True)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))
    dp.add_handler(CommandHandler("procurar", procurar, send_photo))
    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
    main()
  • Welcome to Stackoverflow in English. As the name suggests, the official language used here is Portuguese. So, could you please translate your question? If you prefer, you can also ask the same question on the Stackoverflow website.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.