API

Bot

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

Bases: object

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

action(trigger: str)

Decorator for creating handlers for actions

Parameters:
  • trigger – type of trigger action

  • type – str

attachment(trigger: str)

Decorator for creating handlers for attachments

Parameters:
  • trigger – type of trigger attachment

  • type – str

delete_message(peer_id: int, cmids: list)

Deleting message from group chat, if author is not admin

Parameters:
  • peer_id (int) – id of chat where you want to delete messages

  • cmids (list) – list of conversations ids of message, which you want to delete

message(trigger: str | None = None)

Decorator for creating handlers for messages

Parameters:
  • trigger – trigger message for command. None for default answer

  • type – str

on(event: str, callback: Callable, trigger: str | None = None)

Creating handler for events in longpoll listen

Parameters:
  • event (str) – Event type. You can take in from Types

  • callback (Callable) – Function, which is executed, when event triggers

  • trigger (str) – Trigger for event. Command for message or type of event for other

parse_message(message: dict)

Closed method for parsing message

Parameters:

message (dict) – message dict from event object

send_api_method(method: str, payload: dict)

Sending some vk api method

Parameters:
  • method (str) – VK api method

  • payload (dict) – dict of data to send in method

send_message(peer_id: int, text: str, keyboard: str | Keyboard | None = None)

Sending message in chat

Parameters:
  • peer_id (int) – id of chat, where you want to send message

  • text (str) – text of message you wanted to send

  • keyboard (str | Keyboard) – [OPTIONAL] Keyboard for user, if needed. Takes Keyboard class or json string

start(callback: Callable)

Creating handler for “start” button in private messages

Parameters:

callback (Callable) – Function, which is executed, when button is pushed

start_polling(callback: Callable | None = None)

Starting polling messages from users

Parameters:

callback (Callable) – [OPTIONAL] Function, which would be executed, when bot is started

Keyboard

This class based on vk_api.keyboard.VkKeyboard

class pyvkbot.Keyboard(one_time: bool = False, inline: bool = False)

Bases: VkKeyboard

Keyboard for vk bot. Extends vk_api.keyboard.VkKeyboard

Parameters:
  • one_time (bool) – [OPTIONAL. DEFAULT: False] If true, keyboard closes when user pushes the buttons

  • inline (bool) – [OPTIONAL. DEFAULT: False] If ture, keyboard will be inline