luckydonald/teleflask

AttributeError: 'Teleflask' object has no attribute '_username'

xxott opened this issue · 1 comments

xxott commented

I got this error

  File "/Users/admin/Devel/selfmarket.io/backend/app.py", line 78, in <module>
    from bot.start import bot
  File "/Users/admin/Devel/selfmarket.io/backend/bot/start.py", line 12, in <module>
    def start(update, text):
  File "/Users/admin/Devel/selfmarket.io/backend/venv/lib/python3.8/site-packages/teleflask/server/mixins.py", line 451, in register_command
    self.add_command(command, func, exclusive=exclusive)
  File "/Users/admin/Devel/selfmarket.io/backend/venv/lib/python3.8/site-packages/teleflask/server/mixins.py", line 472, in add_command
    for cmd in self._yield_commands(command):
  File "/Users/admin/Devel/selfmarket.io/backend/venv/lib/python3.8/site-packages/teleflask/server/mixins.py", line 571, in _yield_commands
    yield syntax.format(command=command, username=self.username)
  File "/Users/admin/Devel/selfmarket.io/backend/venv/lib/python3.8/site-packages/teleflask/server/base.py", line 247, in username
    return self._username
AttributeError: 'Teleflask' object has no attribute '_username'
Sentry is attempting to send 1 pending error messages

This is my current code:
app.py

if os.getenv('TELEGRAMBOT_API_KEY', False):
    from bot.start import bot
    bot.init_app(app)

start.py

from teleflask.messages import TextMessage
from teleflask import Teleflask
import os

bot = Teleflask(os.getenv('TELEGRAMBOT_API_KEY'))

@bot.command("start")
def start(update, text):
    # update is the update object. It is of type pytgbot.api_types.receivable.updates.Update
    # text is the text after the command. Can be empty. Type is str.
    return TextMessage("<b>Hello!</b> Thanks for using @" + bot.username + "!", parse_mode="html")

what's wrong ?

I have the same issue