Search code examples
python-3.xtelebot

telebot missing 1 required positional argument: 'message'


i'm trying to make a telegram bot (telebot) i am having a problem with my code

@bot.message_handler(commands=['testes'])
def testes(send_photo,message):
    qr75 = open('qr75.jpg', 'rb')
    bot.send_photo(send_photo.chat.id, qr75)
    bot.send_message(message.chat.id'Hallo')

and i got this error

TypeError: testes() missing 1 required positional argument: 'message'

what should I fix? sorry I'm a beginner


Solution

  • I think there's a little mix up in the function arguments going on. Here's the documentation on @bot.message_handler https://pytba.readthedocs.io/en/latest/sync_version/index.html#telebot.TeleBot.message_handler

    As a parameter to the decorator function, it passes telebot.types.Message object.

    Therefore, your function testes should expect only one argument - message.

    I changed your code a bit, now it should work:

    @bot.message_handler(commands=['testes'])
    def testes(message):
        qr75 = open('qr75.jpg', 'rb')
        bot.send_photo(message.chat.id, qr75)
        bot.send_message(message.chat.id, 'Hallo')
    

    (also added a comma on the last row)

    Hope that helps!