как импортировать txt файл в беседу вк

Как импортировать содержимое txt файл в беседу. Надо что бы,на любое текст,бот отправлял все строки из файла txt.

Вот образец кода,что я собрал,но ни чего у меня не получилось,пишу в беседе привет,и ответа нет.

import vk_api, json
from vk_api.longpoll import VkLongPoll, VkEventType
from config import main_token

vk_session = vk_api.VkApi(token = main_token)
longpoll = VkLongPoll(vk_session)

#file = open("myfile.txt", encoding="utf-8" )
#print( file.read() )

from importlib import resources
#with resources.open_text("books", "data.txt")
#file = open('data.txt', 'w')            # open output file object: creates
#file.close( )                           # closed on gc and exit too
#with resources.open_text("books", "data.txt")
#f = open('data.txt','r')
#file.readlines()

#handle = open("data.txt", "r")
#data = handle.read()
#print(data)
#handle.close()

#f = open('data.txt', 'r')

#f = open('data.txt')
#for line in f:line
#'\n'
#'The end.\n'
#'\n'


#file = open('data.txt', 'r', encoding = 'UTF-8')
#body = file.read()
#file.close()

#input(body)

#file = open('data.txt', 'r')             # open input 

решетки означают,что я проверил их все,и спрятал их от питона.

А вот,этот код рабочий,но без импорта из txt.

import vk_api, json
from vk_api.longpoll import VkLongPoll, VkEventType
from config import main_token

vk_session = vk_api.VkApi(token = main_token)
longpoll = VkLongPoll(vk_session)

def sender(id, text):
    vk_session.method('messages.send', {'chat_id' : id, 'message' : text, 'random_id' : 0})

for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        if event.to_me:
            if event.from_chat:

                msg = event.text.lower()
                id = event.chat_id

                if msg in ['пока', 'привет']:
                    sender(id, f'@{event.user_id}, Приветствую тебя!')

Ответы (1 шт):

Автор решения: V-Mor

Вот здесь, по сути, дан ответ на Ваш вопрос, т.к. единственное, что у Вас не получилось, – считать текст из файла.

Теперь, если перейти к Вашему коду, реализовать нужное можно как-то так:

import vk_api, json
from vk_api.longpoll import VkLongPoll, VkEventType
from config import main_token

vk_session = vk_api.VkApi(token = main_token)
longpoll = VkLongPoll(vk_session)

def sender(id, text):
    vk_session.method('messages.send', {'chat_id' : id, 'message' : text, 'random_id' : 0})

for event in longpoll.listen():
    if event.type == VkEventType.MESSAGE_NEW:
        if event.to_me:
            if event.from_chat:

                msg = event.text.lower()
                id = event.chat_id

                if msg != '':
                    with open('<Название файла>.<расширение>') as text_file:
                        text = text_file.read()
                        sender(id, text)
→ Ссылка