E
E
egorlisss2019-04-14 02:56:55
JavaScript
egorlisss, 2019-04-14 02:56:55

How to extract 2nd word of sentence in hearCommand?

B vk.updates.hearused to extract words from a sentence. It doesn't come out like that. message.$match[1]hearCommand

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2019-04-14
@egorlisss

In the examples, hearCommand is a very simple wrapper around vk.updates.hear . In implementation, it works like this:

hearCommand('test', (context) => {});
// Аналогична данной запись
vk.updates.hear(
  [
    (text, { state }) => (
      state.command === 'test'
    ),
    '/test'
  ],
  (context) => {}
);

Example with 3 arguments
hearCommand('test', /test (.+)/i, (context) => {});
// Аналогична данной запись
vk.updates.hear(
  [
    (text, { state }) => (
      state.command === 'test'
    ),
    /test (.+)/i
  ],
  (context) => {}
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question