Skip to content

Tutorial

Short tutorial to create and run simple bot

Installation

pip install vkpybot
poetry add vkpybot

Importing

import vkpybot as vk

Creating bot instance

1
2
3
4
import vkpybot as vk

token = "VK_API_TOKEN"
bot = vk.Bot(access_token=token)

Adding command

import asyncio

import vkpybot as vk

token = "VK_API_TOKEN"
bot = vk.Bot(access_token=token)


@bot.command
async def timer(message: vk.Message, minutes: int):
    await message.reply(f'Timer set for {minutes} minutes')
    await asyncio.sleep(minutes * 60)
    return 'Timer finished'

Starting bot

import asyncio

import vkpybot as vk

token = "VK_API_TOKEN"
bot = vk.Bot(access_token=token)


@bot.command
async def timer(message: vk.Message, minutes: int):
    await bot.session.reply(message, f'Timer set for {minutes} minutes')
    await asyncio.sleep(minutes * 60)
    return 'Timer finished'

bot.start()