如何将(更新:update,context:callbackContext)传递给我的功能而无需使用处理程序

发布于 2025-02-05 05:33:18 字数 616 浏览 3 评论 0原文

我正在制作用于处理YouTube播放列表的电报机器人。

我有2个功能,并且两个功能都有(更新:更新,上下文:callbackContext) gragmonse。

使用MessageHandler从MAIN调用第一个功能,并且它在没有错误的情况下运行。

但是第二个是从函数1中调用的。

我想知道如何在没有处理程序的情况下通过那些参数。我想以一种使用update.message及其内部功能接受的方式说function2()

这是一个想法的示例:

def check_url(update: Update, context: CallbackContext):
    get_videos_ids()

def get_videos_ids(update: Update, context: CallbackContext):
    some code that use upadte.functions

if __name__ == "__main__":
    updater.dispatcher.add_handler(MessageHandler(Filters.all, check_url))

I'm making Telegram bot for processing Youtube playlists.

I have 2 functions, and both of them have (update:Update, context: callbackContext) arguments.

The first function is called from main using messageHandler and it runs without errors.

But the second one is called from function 1.

I want to know how to pass those arguments without handlers. I want to say function2() in such a way that accept using update.message and other functions inside it.

Here is an example for the idea:

def check_url(update: Update, context: CallbackContext):
    get_videos_ids()

def get_videos_ids(update: Update, context: CallbackContext):
    some code that use upadte.functions

if __name__ == "__main__":
    updater.dispatcher.add_handler(MessageHandler(Filters.all, check_url))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2025-02-12 05:33:18

只需将更新和上下文传递给下一个功能:

def check_url(update: Update, context: CallbackContext):
    get_videos_ids(update, context)

def get_videos_ids(update: Update, context: CallbackContext):
    some code that use update.functions

if __name__ == "__main__":
    updater.dispatcher.add_handler(MessageHandler(Filters.all, check_url))

Just pass down the update and the context to the next function as such:

def check_url(update: Update, context: CallbackContext):
    get_videos_ids(update, context)

def get_videos_ids(update: Update, context: CallbackContext):
    some code that use update.functions

if __name__ == "__main__":
    updater.dispatcher.add_handler(MessageHandler(Filters.all, check_url))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文