-1

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:\Users\baron_btjit4i\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\baron_btjit4i\Desktop\Autrebot\Cogs\ticket.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'
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Marcucus _
  • 88
  • 10

1 Answers1

0

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 
Ayaz Khan
  • 104
  • 1
  • 9