英文:
How to correct this issue, Aiogram, Trelegram
问题
我正在制作一个Telegram机器人,问题是用户必须接受政策,当用户点击接受时,机器人只显示加载消息。
问题视频:https://drive.google.com/file/d/1yAZl0VDn_tisBsHAaJ2udyfnaW-G9IOH/view?usp=sharing
我的代码:https://github.com/user515244/code.git
英文:
I a making a telegram bot, and the problem is that user has to accept policy and when user click accept the bot just shows loading message
Video with the problem: https://drive.google.com/file/d/1yAZl0VDn_tisBsHAaJ2udyfnaW-G9IOH/view?usp=sharing
答案1
得分: 0
-
在第37行有一个拼写错误(confirm_correct1而不是confirm_correct)。
-
要处理下一个状态,你只需要下一个状态,否则它将不会切换。这就是有限状态机的工作原理。
在你的类中添加以下内容:
state_name = State()
在处理程序中添加以下内容,其中text=confirm_correct和text=go_back(请不要给它们的函数取相同的名称,名称应该解释函数的作用):
@dp.callback_query_handler(text="confirm_correct", state=SomeState.state_name)
...
@dp.callback_query_handler(text="go_back", state=SomeState.state_name)
在handle_accept_policy中设置状态:
if amount and wallet:
await callback.message.edit_text(f"Amount: {amount}\nWallet: {wallet}\n\nIs everything correct?",
reply_markup=accept_menu)
await SomeState.state_name.set()
就是这样。
英文:
-
You have a typo in line 37 (confirm_correct1 instead of confirm_correct)
-
To handle the next state, you simply need the next state, otherwise it will not be switched. This is how FSM works.
Add to your class:
state_name = State()
Add to your handlers with text=confirm_correct and text=go_back (please don't give the functions in them the same names, names should explain what the function does) the following:
@dp.callback_query_handler(text="confirm_correct", state=SomeState.state_name)
...
@dp.callback_query_handler(text="go_back", state=SomeState.state_name)
Add to handle_accept_policy setting the state:
if amount and wallet:
await callback.message.edit_text(f"Amount: {amount}\nWallet: {wallet}\n\nIs everything correct?",
reply_markup=accept_menu)
await SomeState.state_name.set()
And that'll be it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论