使用Telethon在一个Python脚本中创建多个机器人

发布于 2025-01-18 20:31:03 字数 264 浏览 2 评论 0原文

我想在同一python脚本中创建多个机器人, 这些机器人相似,它们之间的唯一区别是令牌。

我想到的第一个想法是创建一个类包含bot脚本,然后每次创建一个新的bot时,我都会创建此类的新实例,并将机器人令牌传递给初始化函数。

我不确定是否可以使用Telethon在类内部创建一个机器人,我看到的所有示例都在使用功能和装饰。那么Telethon(MTPROTO)是否支持多个实例一起运行?

还是我需要同时运行它们?

代码示例对我非常有帮助。

谢谢。

I want to create multiple bots in the same python script,
these bots are similar, the only difference between them is the tokens.

the first idea that comes to my mind is to create a class contains the bot script, then I create new instance of this class each time I want to create a new bot, and pass the bot token to the init function.

I'm not sure if I can create a bot inside a class using telethon, all examples that I saw are using functions and decorations. Then does telethon (MTProto) supports multiple instances running together ?

Or do I need to run them concurrently ?

code examples will be very helpful for me.

Thanks.

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

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

发布评论

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

评论(1

慵挽 2025-01-25 20:31:03

在循环中,其他代码不会执行,而无需结束循环。

但是OFC您可以上课,然后

进行多线程

运行多个线程类似于同时运行多个不同的程序

单击此处以获取有关多线程的更多信息

我希望它有用。

In a loop the other codes wont execute without the ending of the loop.

But ofc you can make a class and then

do multithreading

Running several threads is similar to running several different programs concurrently

Click here for more about Multithreading

I hope it was helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文