问题
I am attempting to save the most recent message of every user to a JSON file attached to their user ID. Something will be written to the file but it's not the raw message.
async def on_message(self, msg):
if msg.author == self.client.user:
return
with open("users.json") as f:
users = json.load(f)
users[str(msg.author.id)]['response'] = str(msg)
with open('users.json', 'w') as f:
json.dump(users, f)
I expect the output to be the raw message of what the user sends but instead I get something along the lines of
"<Message id=585702897673699338 pinned=False author=<Member id=344030587884929025 name='Siiant' discriminator='5767' bot=False nick=None guild=<Guild id=555525798090768446 name='Bot Test' chunked=True>>>"
回答1:
That's the string representation of the Message
object. To get the content of the message, use msg.content
来源:https://stackoverflow.com/questions/56469967/issue-saving-message-to-json-file-discord-py-rewrite