P
P
Pro100Vova56262020-05-14 16:24:11
Python
Pro100Vova5626, 2020-05-14 16:24:11

How to send text from a file?

We need the bot to send a message with the text taken from the .txt file

. I wrote the following code:

@client.event
async def on_message(message):
    msg = message.content.lower()

    await client.process_commands(message)  # чтобы работали команды с префиксам

    if message.author.bot:  # Игнорит сообщения от ботов
        return

    if msg in report_words:
        with open(f'{getcwd()}\почему.txt', 'r') as file:
            text = file.read()
        await message.channel.send(text)

But the bot sends
<_io.TextIOWrapper name='D:\path to file\why.txt' mode='r' encoding='cp1251'>

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