将消息保存到 json 文件 discord.py rewrite [英] Issue saving message to json file discord.py rewrite
本文介绍了将消息保存到 json 文件 discord.py rewrite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将每个用户的最新消息保存到附加到其用户 ID 的 JSON 文件中.某些内容将写入文件,但不是原始消息.
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>>>"
推荐答案
这是 Message
对象的字符串表示.要获取消息的内容,请使用 msg.内容
That's the string representation of the Message
object. To get the content of the message, use msg.content
这篇关于将消息保存到 json 文件 discord.py rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文