0

So.. I want to know how could I do the classic events work with my json variables.

Let me explain, I created a json file which memorates the, channelid, reactions, assigned role, and total reactions, of a message. For example if I run the command : .r <messageID> <emoji> <role> add

The JSON File writes this :

{
  <messageID> :{
       'channelID' : <channelID of the message>
       'reaction(1)' : '<emoji>'  //unicode name value | I used "unicode.name(emoji)"
       'assigned role(1)' : '<role>'
       'total rrs' : 1
  }
}

I ve made everything, but the events, I can t figure them out, I tried with payload, that on_reaction_raw_add/remove functions, but it does not work, or supposely I don t know how to use them..

I also tried with the other ones, on_reaction_add/remove() but I can't figure them out, it does not work, could omeone help me, in case you need more details about the code, you can comment below and I ll edit the message or reply yours.

Thank you,

RVZWN.

RVZWN
  • 15
  • 8

1 Answers1

0

I assume the events in general, there is an event called 'on_reaction_add' which lets you do something whenever you add a reaction ( 'on_reaction_remove' for when you remove one ) Inside this method, you can get the reaction from the user who placed it.

in the reaction value you can get the actual message by doing reaction.message ( Discord.Message ) and reaction.emoji ( which gives you the actual emoji )

async def on_reaction_add(self, reaction: discord.Reaction, user: 
                          discord.Member):
    # Rest of code here about reactions, dumping to json and things

If I didn't answer it correctly then specify what you're asking, If you need anything else I'll be more than happy to help.

Amit Yanay
  • 32
  • 4
  • I know that, I need help coding the function, because I m rusty working with jsons, if you could figure it out, I'd be more than happy, ty <3 – RVZWN Feb 18 '22 at 01:20
  • There's [link](https://www.geeksforgeeks.org/reading-and-writing-json-to-a-file-in-python/) site where you can learn how to interact with a JSON file, It's a good way to learn how to do it NOTE: If you want to dump the data to a JSON file just use [pprint](https://stackoverflow.com/questions/9170288/pretty-print-json-data-to-a-file-using-python) module, it'll print it in a pretty way instead of everything clogged up – Amit Yanay Feb 18 '22 at 07:26