为什么它只返回 json 的值而不是密钥?
Why it retrun me only the value of the json and not the key?
我想检查添加的反应(不和谐)是否在正确的频道和正确的消息中。
我将频道 ID 和消息 ID 存储在 .json 文件中
但是 python 不想发送密钥的值,我不知道如何解决这个问题
{"931966019612864623": "931966020808228922"}
<== 这是我的 json 文件
931966020808228922
<== 这就是 python return
这是我的代码
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.items()
替换 for key in distros_dict.keys()
,但是 return 我遇到了这个错误:
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'
非常感谢!
使用
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
我想检查添加的反应(不和谐)是否在正确的频道和正确的消息中。 我将频道 ID 和消息 ID 存储在 .json 文件中 但是 python 不想发送密钥的值,我不知道如何解决这个问题
{"931966019612864623": "931966020808228922"}
<== 这是我的 json 文件
931966020808228922
<== 这就是 python return
这是我的代码
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.items()
替换 for key in distros_dict.keys()
,但是 return 我遇到了这个错误:
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'
非常感谢!
使用
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