Usage

Creating bots

First of all you should get the api_key for you bot using the oficial docs

To create the bot, you can use the pyvkbot.Bot() class:

class pyvkbot.Bot(token: str, group_id: int, main_chat: int | None = None, logging: bool = True)

Main class for working with vk bot

Parameters:
  • token (str) – VK access token

  • group_id (int) – id of your group

  • main_chat (int) – id of main chat for bot

  • logging (bool) – if True - logging in stdout by loguru.logger

The token and group_id parameter should be defined. Otherwise, Bot will raise an exception

Getting started

Create the bot

import os

from pyvkbot import Bot

token = os.getenv("TOKEN")
group_id = os.getenv("GROUP_ID")

bot = Bot(token=token, group_id=group_id)

Bind the commands

@bot.message("Start")
 def hello(bot: Bot, message: dict[str, str]):
     bot.send_message(peer_id=message["peer_id"], text="Hello there!")


@bot.message()
def default(bot: Bot, message: dict[str, str]):
    bot.send_message(peer_id=message["peer_id"], text="Sorry, i don't understand you")

Start the bot

bot.start_polling(lambda: print("Bot started"))

Enjoy your bot!