Why it retrun me only the value of the json and not the key?

Question:

I want to check if the reaction (in discord) that was added is in the right channel and on the right message.
I stored the channel id and message id in a .json file
But python does not want to send the value of the key and i don’t know how to solve this problem

{"931966019612864623": "931966020808228922"} <== this is my json file

931966020808228922 <== this is what python return

Here is my code

        elif payload.emoji.name == ' ':
            
            if payload.user_id != self.client.user.id:
                count = 0
                with open(ticket_msg, 'r') as f:
                    distros_dict = json.load(f)
                    await channell.send(distros_dict)

                for key in distros_dict.keys():
                    channel_id = distros_dict.get(key)
                    await channell.send(str(channell.id) + ' ' + str(channel_id))

                    if int(channell.id) == int(channel_id):
                        count+=1

                if count > 0:

                    await channell.send("ok")
                else:
                    return 

I’ve tested to replace for key in distros_dict.keys() by for key in distros_dict.items() , but it return me this error:

Ignoring exception in on_raw_reaction_add
Traceback (most recent call last):
  File "C:Usersbaron_btjit4iAppDataLocalProgramsPythonPython39libsite-packagesdiscordclient.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "c:Usersbaron_btjit4iDesktopAutrebotCogsticket.py", line 170, in on_raw_reaction_add
    if int(channell.id) == int(channel_id):
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
Asked By: Marcucus _

||

Answers:

use

for key, value in distros_dict.items()

which i updated

        elif payload.emoji.name == ' ':
           
           if payload.user_id != self.client.user.id:
               count = 0
               with open(ticket_msg, 'r') as f:
                   distros_dict = json.load(f)
                   await channell.send(distros_dict)

               for key, value in distros_dict.items():
                   channel_id = key
                   await channell.send(str(channell.id) + ' ' + str(channel_id))

                   if int(channell.id) == int(channel_id):
                       count+=1

               if count > 0:

                   await channell.send("ok")
               else:
                   return 
Answered By: Ayaz Khan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.