0

我想检查添加的反应(不和谐)是否在正确的频道和正确的消息中。我将频道 ID 和消息 ID 存储在 .json 文件中但是 python 不想发送密钥的值,我不知道如何解决这个问题

{"931966019612864623": "931966020808228922"}<== 这是我的 json 文件

931966020808228922<== 这是python返回的

这是我的代码

        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 

我已经测试替换for key in distros_dict.keys()for key in distros_dict.items(),但它返回了这个错误:

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'

多谢 !

4

1 回答 1

0

采用

for key, value in distros_dict.items()

我更新了

        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 
于 2022-01-15T18:11:14.467 回答