1
1
1thater2019-11-24 18:32:11
Python
1thater, 2019-11-24 18:32:11

How to run a bot (VK, PYTHON) on hosting?

Hello ! Wrote a bot for conversations in VK on PYTHON. Now I want to upload it to the hosting (so that the bot works non-stop), and I understand that I don’t understand how to do it at all.
Hosting beget . Installed on the PYTHON 3.8 server, the necessary libraries (vk_api, etc.). And then I don’t understand how I can run the bot on the server.
In working with servers, I am a complete zero, in other words, “I know nothing what to do”.
I know that the server uses a virtual Docker environment.
The server is running Ubuntu 12.04.5 LTS.

Here is an example bot code.

import vk_api
import random
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType

vk = vk_api.VkApi(token="токен")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, 187955020)

def vk_send(message):
    vk.method("messages.send", {"peer_id": event.object.peer_id, "message": message,
                                "random_id": random.randint(-9223372036854775808, 9223372036854775807)})

# проверка на событие - входящее сообщение
for event in longpoll.listen():
    if event.type == VkBotEventType.MESSAGE_NEW:
        if event.object.peer_id != event.object.from_id:
            message = event.object.text.lower()  # сообщение

            if event.object.action == {'type': 'chat_invite_user', 'member_id': -187955020}:
                vk_send('Привет! Вы только что добавили бота *VKBOT* в вашу беседу! Для активации всех функций ' \
                        '*VKBOT* дайте ему доступ ко всей переписке (управление беседой --> дать доступ ко все переписке), ' \
                        'а также зарегистрируйте вашу беседу написав "/reg". ')

            elif message == "gg":
                vk_send("GaGE")


I read that you can use screen + supervisor. I wonder how correct and effective this method is. And then you can hammer nails with a screwdriver, well, you understand.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Milton812, 2019-11-24
@1thater

The easiest way -nohup /path/to/python /path/to/script

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question