Python Discord Bot Saving Text Issue

Viewed 35

I have a discord bot where the purpose is to take text out of a channel, and save it to two files. When I run it, I see the timestamp for changes to both text files updates, but the text doesn't write to the files. I can see on the logfile a bunch of commas, so I know the bot is reading the messages from discord, but it's not writing them, it is leaving the space blank.

import discord

Templetext = 'writefile.txt'
Logfile = 'templelog.txt'
newline = ('\n')
closetemple = 'exit()'
Token = 'my token string'
client = discord.Client()

print('I am on')

@client.event
async def on_ready():
    print('Ready and Listening')

@client.event
async def on_message(message):
        with open(Templetext, "w") as file1:
        file1.write(f" {message.content}")
    with open(Logfile, "a") as file2:
        file2.write(f" {message.content}, {newline}")


client.run(Token)
1 Answers

I solved the issue. it was a discord intents issue, not my code. Signs this is the problem: Note file2.write(f" {message.content}, {newline}"). On the templelog file, the comma was appearing that separates the message content and the newline, indicating the program was writing to the file, but that the contents of the messages were not.

Related