mail-ru-im / bot-python

Bot API for Python
https://teams.vk.com/botapi/
MIT License
83 stars 33 forks source link

Ranaming local variable causing a bug #23

Open evyasonov opened 3 years ago

evyasonov commented 3 years ago

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?

robert-cody commented 3 years ago

Because callbacks called with keyword arguments (not positional).