S
S
sousagemonster2022-04-07 02:31:30
Bots
sousagemonster, 2022-04-07 02:31:30

How to restart the bot?

I added .py files to the directory through the bot

. Now I want to completely restart the bot, by entering the command in the bot itself, i.e. fully load all files with command handlers on a new one.

Does anyone have any ideas how this can be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leonid, 2022-04-07
@bravebug

My bot is launched by the supervisored service, it can restart the script when it completely crashes, but it didn’t work for me to end the bot from the function, the process does not end.
For now I use for telegram (python-telegram-bot)*:

def cmd_restart_service(update, context):
    if update.message.from_user.id == 777777777: # id пользователя
        import subprocess

        update.message.reply_text("будет исполнено...")
        subprocess.run("sudo supervisorctl restart mybotname".split())

And I have no honor for this :)
* External restart commands and such a possibility itself depend on the operating system/service/services/settings where the bot is running.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question