Туториал
Short tutorial to create and run simple bot
Установка
Импорт
Создание объекта бота
| import vkpybot as vk
token = "VK_API_TOKEN"
bot = vk.Bot(access_token=token)
|
Добавление команды
| 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'
|
Запуск бота
| 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()
|