【发布时间】:2020-09-19 23:17:01
【问题描述】:
我目前正在制作一种票务系统。我想通过反应来做到这一点。
当用户点击反应时,会向特定频道发送一条消息。此消息 ID 保存在 JSON 文件中,应分配给单击反应的用户。但是如果我将用户和消息分别保存在 JSON 文件中,我不知道该消息属于哪个用户。如何将消息 ID 分配给用户?
我的代码:
@client.event
async def on_raw_reaction_add(reaction):
ticketmess = 716263100638035969
ticketlog = client.get_channel(716265124771397662)
user = client.get_user(reaction.user_id)
if reaction.message_id == ticketmess and reaction.emoji.id == 680827797165572117:
with open(r'./tickets.json', 'r')as f:
ticketchannels = json.load(f)
if not f"{reaction.user_id}" in ticketchannels:
ticketmess = await ticketlog.send('Ein User braucht Hilfe!')
with open(r'./tickets.json', 'r')as f:
ticketmessages = json.load(f)
ticketmessages[f"{reaction.user_id}"] = f'{user} in {ticketmess.id}'
with open(r'./tickets.json', 'w') as f:
json.dump(ticketmessages, f, indent=4)
【问题讨论】:
标签: python json discord.py