mail-ru-im/bot-python

Ranaming local variable causing a bug

evyasonov opened this issue · 1 comments

Hey

I took an example from documentation:

from bot.bot import Bot
from bot.handler import MessageHandler

TOKEN = "" #your token here

bot = Bot(token=TOKEN)

def message_cb(bot, event):
    bot.send_text(chat_id=event.from_chat, text=event.text)

bot.dispatcher.add_handler(MessageHandler(callback=message_cb))
bot.start_polling()
bot.idle()

The original example works nice. BUT if I rename bot to icq in message_cb function, then the bot does not send messages back to user. Other words, the code below does not work:

from bot.bot import Bot
from bot.handler import MessageHandler

TOKEN = "" #your token here

bot = Bot(token=TOKEN)

def message_cb(icq, event):
    icq.send_text(chat_id=event.from_chat, text=event.text)

bot.dispatcher.add_handler(MessageHandler(callback=message_cb))
bot.start_polling()
bot.idle()

Why is it?

Because callbacks called with keyword arguments (not positional).