E
E
egorlisss2019-03-19 09:27:10
JavaScript
egorlisss, 2019-03-19 09:27:10

HearCommand not defined?

5c908bba82024680564016.jpeg

const {VK, Keyboard } = require('vk-io');
const vk = new VK();
const commands = [];
const {updates, snippets} = vk;
const fs = require("fs");
const request = require('prequest');
  
hearCommand('купить', async(context) => {
 	await context.send('Выберите товар👇')
    await context.send({
    keyboard: Keyboard.keyboard([
      [
        Keyboard.textButton({
        label: 'Skin - 64п. 40р.',
        payload: {
          command: 'skin'
        },
        color: Keyboard.POSITIVE_COLOR
      }),
                Keyboard.textButton({
        label: 'Line - 32п. 15р.',
        payload: {
          command: 'line'
        },
        color: Keyboard.POSITIVE_COLOR
      }),
                Keyboard.textButton({
        label: 'Reshade - 64п. 30р.',
        payload: {
          command: 'reshade'
        },
        color: Keyboard.POSITIVE_COLOR
      }),
      ],
                Keyboard.textButton({
        label: 'Меню',
        payload: {
          command: 'menu'
        },
        color: Keyboard.DEFAULT_COLOR
      }),
                Keyboard.textButton({
        label: '❌',
        payload: {
          command: 'cancel'
        },
        color: Keyboard.NEGATIVE_COLOR
      })
    ],
    {
      oneTime: true
    })
   });
});

vk.updates.hear(/^(?:menu)$/i, async (context) => {
  await context.send('Меню - https://vk.com/page-179859706_56457773')
  
   });
vk.updates.hear(/^(?:1)$/i, async (context) => {
  await context.send('Меню - https://vk.com/page-179859706_56457773')
   });
vk.updates.hear(/^(?:2)$/i, async (context) => {
  await context.send('Меню - https://vk.com/page-179859706_56457773')
   });
vk.updates.hear(/^(?:3)$/i, async (context) => {
  await context.send('Меню - https://vk.com/page-179859706_56457773')
   });

vk.setOptions({
    token: '2709ввв593be38901d2b7603вв47a890d0933a',
    apiMode: 'parallel',
  pollingGroupId: 179859706
});
updates.startPolling()
.then(() => {
  console.log(`Bot started!`);
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2019-03-19
@egorlisss

Well, hearCommand is not defined anywhere, not imported, where did you get this function from?
UPD: ah, you apparently copied somewhere, but not all. Apparently from here https://github.com/negezor/vk-io/blob/07013a339eb3... Then you need to copy more

const { updates } = vk;
const hearCommand = (name, conditions, handle) => {
  if (typeof handle !== 'function') {
    handle = conditions;
    conditions = [`/${name}`];
  }

  if (!Array.isArray(conditions)) {
    conditions = [conditions];
  }

  updates.hear(
    [
      (text, { state }) => (
        state.command === name
      ),
      ...conditions
    ],
    handle
  );
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question