D
D
Dream Fox2020-11-18 03:36:10
Python
Dream Fox, 2020-11-18 03:36:10

How to make a message automatically delete after a while?

I made a bot that sends photos with cats from the conversation to private messages, and in the conversation writes that the photos with cats were sent to L/S. So, so that users do not abuse the command and do not create a flood, it is necessary to auto-delete the message "Sent photos with cats to L / S" after some time (for example: after 5 seconds), but everything goes wrong. Please explain how to implement my idea, what should be added/changed in the code(s)?

import sys
from vk_api.longpoll import VkLongPoll, VkEventType
import vk_api
from datetime import datetime
import random
import time
import get_pictures

token ='токен'
vk_session = vk_api.VkApi(token=token)
session_api = vk_session.get_api()
longpoll = VkLongPoll(vk_session)

def send_message(vk_session, id_type, id, message=None, attachment=None):
    vk_session.method('messages.send',{id_type: id, 'message': message, 'random_id': random.randint(-2147483648, +2147483648), "attachment": attachment})

for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        if event.from_chat:
            if event.text.lower == "котики":
                attachment = get_pictures.get(vk_session, -130670107, session_api)
                print('Запрос на отправку фотографий с котиками выполнен.')
                send_message(vk_session, 'user_id', event.user_id, message=' | Мяу, вот тебе котики. :з', attachment=attachment)
                send_message(vk_session, 'chat_id', event.chat_id, message=' | Отправил фотографии с котиками в Л/С.')
        time.sleep(0.5)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question