So, I'm making a server bot, and I'm trying to make the bot log user messages when they send a file.
... with open("messages.txt", "w") as f: f.write(f'{message.author.name}: "{message.content}" {time.strftime("%H:%I:%M")} {message.guild.name} ') ...
Its somewhat working for some users, but I keep getting errors when others send messages. "UnicodeEncodeError: 'charmap' codec can't encode character 'u2615' in position 0: character maps to " And sometimes it will just clear the file.
Thanks!
Use unicode to parse non-ascii strings. ('u2615' is decoded as ? in UTF-8)
'u2615'
open("messages.txt", "w", encoding='utf-8')
2.1m questions
2.1m answers
60 comments
57.0k users