Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranaming local variable causing a bug #23

Open
evyasonov opened this issue Apr 20, 2021 · 1 comment
Open

Ranaming local variable causing a bug #23

evyasonov opened this issue Apr 20, 2021 · 1 comment

Comments

@evyasonov
Copy link

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
Copy link

Because callbacks called with keyword arguments (not positional).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@evyasonov @robert-cody and others