NodeJS vk api node js

Kecer

Участник
Автор темы
241
11
Проблема заключается в том что, если я пишу боту в лс /test, я получаю ответ test и через 5 секунд я получаю ответ test5, и вроде бы скрипт работает но проблема заключается в том что если я его отправляю в беседу, то после прохождения 5 секунд, мне выдаётся следующая ошибка:

JavaScript:
APIError: Code №100 - One of the parameters specified was missing or invalid: message_id and conversation_message_id is undefined

Вот код с отправкой в чат

JavaScript:
bot.hear(/^(?:\/test)$/i, async msg => {
  const message = await msg.send({ message: 'test', chat_id: 6 });
  setTimeout(() => message.editMessage({ message: "test5" }), 5000);
})
 
Последнее редактирование:

livingflore

Известный
366
320
Ты не понял, смотри я пишу в лс команду боту, он отправляет сообщение test в беседу с айдишником 6 и в беседе редачит сообщение. А в беседе пишешь команду и он на эту команду даёт ответ в беседе и там же редачит.
JavaScript:
bot.hear(/^(?:\/test)$/i, async msg => {
    if (msg.peerType == 'user') {
    const message = await vk.api.messages.send({ message: 'Test 1', chat_id: 6, random_id: Math.floor(Math.random() * 892743012) });
    setTimeout(() => vk.api.messages.edit({ message: 'Test 2', peer_id: 2000000006, message_id: message }), 5000);
    }
  })
так?
 

Kecer

Участник
Автор темы
241
11
JavaScript:
bot.hear(/^(?:\/test)$/i, async msg => {
    if (msg.peerType == 'user') {
    const message = await vk.api.messages.send({ message: 'Test 1', chat_id: 6, random_id: Math.floor(Math.random() * 892743012) });
    setTimeout(() => vk.api.messages.edit({ message: 'Test 2', peer_id: 2000000006, message_id: message }), 5000);
    }
  })
так?
Ща попробую

JavaScript:
bot.hear(/^(?:\/test)$/i, async msg => {
    if (msg.peerType == 'user') {
    const message = await vk.api.messages.send({ message: 'Test 1', chat_id: 6, random_id: Math.floor(Math.random() * 892743012) });
    setTimeout(() => vk.api.messages.edit({ message: 'Test 2', peer_id: 2000000006, message_id: message }), 5000);
    }
  })
так?
APIError: Code №100 - One of the parameters specified was missing or invalid: message_id and conversation_message_id is undefined

Я не понимаю, пкд выбивает одну и ту же ошибку
 
Последнее редактирование:

Kecer

Участник
Автор темы
241
11
полную ошибку скинь
JavaScript:
(node:4600) UnhandledPromiseRejectionWarning: APIError: Code №100 - One of the parameters specified was missing or invalid: Only conversation_message_id or message_id field should be specified
    at SequentialWorker.execute (C:\Users\KIR\Desktop\google sheets base\node_modules\vk-io\lib\index.js:1670:39)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4600) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4600) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
 

livingflore

Известный
366
320
JavaScript:
(node:4600) UnhandledPromiseRejectionWarning: APIError: Code №100 - One of the parameters specified was missing or invalid: Only conversation_message_id or message_id field should be specified
    at SequentialWorker.execute (C:\Users\KIR\Desktop\google sheets base\node_modules\vk-io\lib\index.js:1670:39)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4600) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4600) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
замени vk.updates.start() на vk.updates.start().catch(console.error), воспроизведи ошибку еще раз и скинь ее
 

Kecer

Участник
Автор темы
241
11
замени vk.updates.start() на vk.updates.start().catch(console.error), воспроизведи ошибку еще раз и скинь ее
Там и так так стоит
1656173010938.png
 

Kecer

Участник
Автор темы
241
11
обнови ноду и перепиши все на тс
а, и еще, используй не npm, а pnpm
Обновил ноду

JavaScript:
C:\Users\KIR\Desktop\google sheets base\node_modules\vk-io\lib\index.js:1670
            this.handleError(request, new APIError(response.error));
                                      ^

APIError: Code №100 - One of the parameters specified was missing or invalid: message_id and conversation_message_id is undefined
    at SequentialWorker.execute (C:\Users\KIR\Desktop\google sheets base\node_modules\vk-io\lib\index.js:1670:39)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  code: 100,
  params: [
    { key: 'method', value: 'messages.edit' },
    { key: 'oauth', value: '1' },
    { key: 'v', value: '5.131' },
    { key: 'message', value: 'Test 2' },
    { key: 'peer_id', value: '2000000006' },
    { key: 'message_id', value: '0' }
  ],
  [cause]: undefined
}
Теперь вот такая ошибка
 

Kecer

Участник
Автор темы
241
11
каким образом 0, если message_id указан? нихера не понял
ты просто скопировал и вставил мой код, ничего не меняя, верно?
да, вот я тоже на это внимание обратил сам не понимаю почему 0
 

Kecer

Участник
Автор темы
241
11
ты можешь скинуть мне фулл код без токена и без других команд?
JavaScript:
const { VK, getRandomId, Keyboard } = require('vk-io')
const vk = new VK({ token: "token" })
const { HearManager } = require('@vk-io/hear')
const fs = require('fs');
const bot = new HearManager('<MessageContext>')

vk.updates.on('message_new', bot.middleware)

bot.hear(/^(?:\/test)$/i, async msg => {
  if (msg.peerType == 'user') {
  const message = await vk.api.messages.send({ message: 'Test 1', chat_id: 6, random_id: Math.floor(Math.random() * 892743012) });
  setTimeout(() => vk.api.messages.edit({ message: 'Test 2', peer_id: 2000000006, message_id: message }), 5000);
  }
})

console.log("ok");
vk.updates.start().catch(console.error);

Вот фулл код
 

livingflore

Известный
366
320
JavaScript:
const { VK, getRandomId, Keyboard } = require('vk-io')
const vk = new VK({ token: "token" })
const { HearManager } = require('@vk-io/hear')
const fs = require('fs');
const bot = new HearManager('<MessageContext>')

vk.updates.on('message_new', bot.middleware)

bot.hear(/^(?:\/test)$/i, async msg => {
  if (msg.peerType == 'user') {
  const message = await vk.api.messages.send({ message: 'Test 1', chat_id: 6, random_id: Math.floor(Math.random() * 892743012) });
  setTimeout(() => vk.api.messages.edit({ message: 'Test 2', peer_id: 2000000006, message_id: message }), 5000);
  }
})

console.log("ok");
vk.updates.start().catch(console.error);

Вот фулл код
я заменил token на свой токен и ничего не меняя попытался воспроизвести ошибку, у меня ее нет, все работает, хз чем помочь

upd: вру, айди чата поменял