如何修复这个问题,Aiogram,Telegram

huangapple go评论93阅读模式
英文:

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

My code:https://github.com/user515244/code.git

答案1

得分: 0

  1. 在第37行有一个拼写错误(confirm_correct1而不是confirm_correct)。

  2. 要处理下一个状态,你只需要下一个状态,否则它将不会切换。这就是有限状态机的工作原理。

在你的类中添加以下内容:

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()

就是这样。

英文:
  1. You have a typo in line 37 (confirm_correct1 instead of confirm_correct)

  2. 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.

huangapple
  • 本文由 发表于 2023年6月18日 19:50:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500396.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定