Parvat R
Posted on August 12, 2021
Define a client in different way:
/main.py
:
import pyrogram
client = pyrogram.Client("Session-Name")
/config.ini
:
[pyrogram]
api_id=1234567
api_HASH=1108f129f7afa345076448421e535bbd
bot_token=1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
You can get your api_id
, api_hash
from telegram. And, you can get the token from @botfather
Do long time process, without disturbing the bot
import _thread
def some_long_process(param1, param2):
# do something that takes long time
param2.reply_text('Process Over.')
...
@client.on_message(
pyrogram.filters.command('do_big')
)
def do_big(_c, message):
_thread.start_new_thread(some_long_process, (_c, message))
You can pass on the client
and the message parameter
to some function, which takes a long time to complete, and has to notify the user when it completes. During this process, some times the bot might stop responding to other users, or become slow.
So, use _thread
module to start a new thread which runs in background
without disturbing your bot, and making it faster to the core.
💖 💪 🙅 🚩
Parvat R
Posted on August 12, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.