E
E
eshran2020-06-08 14:28:26
In contact with
eshran, 2020-06-08 14:28:26

I can't delete a message using the VK API, what should I do?

Hello!
I tried to create a function to delete a message, but for some reason it does not work.
Through a request on the site, everything turns out, through the code it doesn’t.
Here is the code:

await vk.api.messages.getByConversationMessageId({ peer_id: 2000000000 + message.chatId, conversation_message_ids: message.conversationMessageId, v: '5.80' }).then(async (res) => {
    await vk.api.messages.delete({ message_ids: res.items[0].id, delete_for_all: 1 })
    vk.api.call("messages.removeChatUser", {chat_id: message.chatId, user_id: message.senderId })
    return message_b(message.chatId, ` Отправка ссылок в этой беседе запрещено.`)
})

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stepan Kuznetsov, 2020-06-08
@eshran

It all depends on who the bot you need is, if the bot is a group and works by
adding a group to chats, then alas, nothing can be done, the API does not store message IDs for groups, which is why you cannot delete messages from the group side, the only the way is to delete messages on behalf of the user or delete them manually.
If you use the bot from the side of the user's page, then try to console what the API gives out and reason and eliminate based on this.
As I understand it, the vk-io library is used in the code, therefore I adapted the code for it.

const otherMessage = (await vk.api.messages.getByConversationMessageId({
  peer_id: 2000000000 + message.chatId,
  conversation_message_ids: message.conversationMessageId,
})).items[0]

console.log(otherMessage)

await Promise.all([
  vk.api.messages.delete({
    message_ids: otherMessage.id,
    delete_for_all: 1,
  }),
  vk.api.messages.removeChatUser({
    chat_id: message.chatId,
    user_id: message.senderId,
  })
])

return message_b(message.chatId, 'Отправка ссылок в этой беседе запрещена.')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question