我想檢查添加的反應(不和諧)是否在正確的頻道和正確的訊息中。我將頻道 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'
多謝 !
uj5u.com熱心網友回復:
利用
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/412326.html
標籤:
