Skip to content
Advertisement

discord.py : Sort message ID in a JSON file by user

I’m currently in the process of making a kind of ticket system. I want to do that through a reaction.

When a user clicks on the reaction, a message is sent to a specific channel. This message ID is saved in a JSON file and should be assigned to the user who clicked on the reaction. But if I save the user and the message individually in the JSON file, I don’t know which user the message belongs to. How can I assign the message ID to a user?

My Code:

JavaScript

Advertisement

Answer

The code would look something like:

JavaScript

You don’t need the f"{user} in {ticketmsg.id}" because you can get the user from the key. Besides, usernames can change, so putting it in the file would prove to be not very useful.
If you wish to get the user’s name, just load in the keys from the json and use client.get_user(ID_HERE).

If you want to search for a user based off of a specific message ID, you can iterate through a dictionary like so:

JavaScript

I’m hoping I understood your question correctly, if not, I’ll be happy to edit my answer after some clarification.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement