Issue saving message to json file discord.py rewrite

淺唱寂寞╮ 提交于 2019-12-02 18:35:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!