如何修复我的 aiogram 代码?调度员问题

How to repair my aiogram code? Dispatcher problem

我想输入“/Hello”后输出“Hi”。它正在与

合作
@dp.message_handler(commands=["Hello"]) 

但没有

def register_handlers_client(dp : Dispatcher):
    dp.register_message_handler(raspisanije, commands=["Hello"])

有什么问题?

TOKEN = 'TOKEN'
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)


btn1 = KeyboardButton("/Hello")
mainMenu1 = ReplyKeyboardMarkup(resize_keyboard = True).add(btn1)

# @dp.message_handler(commands=["Hello"]) 
async def raspisanije(message: types.Message):
    await bot.send_message(message.from_user.id, "Hi")

def register_handlers_client(dp : Dispatcher):
    dp.register_message_handler(raspisanije, commands=["Hello"])

if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)

register_handlers_client 函数未被调用。 您需要在 if __name__ == "__main__": 中调用它,这样它就变成了:

if __name__ == "__main__":
    register_handlers_client(dp)
    executor.start_polling(dp, skip_updates=True)