你好,我的json文件有问题。我想在我的json文件中加载以删除用户的用户消息,这些用户被写在这个文件(id(中。为了检查客户端是否得到它,我说控制台在json文件加载后打印它,如果它工作正常,第二次应该打印DONE。
这是我的密码。
@commands.Cog.listener()
async def on_message(self, message):
with open('./bot_config/blocked_users.json', 'r') as json_file:
json_dict = json.load(json_file)
print(message.author.id)
if message.author.id in json_dict:
await message.delete()
await message.author.send('Du darfst keine Nachrichten verschicken, da du blockiert wurdest! :smile:')
print('DONE')
return
我知道问题在上
if message.author.id in json_dict:
我想知道如何更换它,因为我不知道。我也试过
if message.author.id in json_file:
但什么也没发生。
edit:这是我的json文件。
{
"blockedUser": [
805047615128469534
]
}
json.load
只是根据json将整个文件转换为字典或列表。因此,json将被转换为一个带有单个关键字blockedUser
的字典。因此,如果用户在该键的值中,我们就有了。
if message.author.id in json_dict['blockedUser']:
#user is blocked