path = os.path.dirname(os.path.realpath(__file__))
if os.path.exists(path + '/nomore.json'):
blacklist = json.loads(open("%s/nomore.json" % (path)).read())
if cmd.lower() == "add":
try:
username = await self.bot.get_user_info(usr)
blacklist["blacklist"].append(int(usr))
json.dump(blacklist, (open("%s/nomore.json" % (path), 'w')))
await self.bot.say('`%s` added to blacklist' % (username))
except Exception as e:
await self.bot.say(e)
elif cmd.lower() == "remove":
try:
for ids in blacklist["blacklist"]:
if ids == int(usr):
blacklist["blacklist"].remove[ids]
json.dump(blacklist, (open("%s/nomore.json" % (path), 'w')
await self.bot.say('Remove invoked')
except Exception as e:
await self.bot.say(e)
我正在使用.append()向JSON对象添加值,但我不确定按值从数组中删除值的正确方法是什么。在
JSON文件如下所示:
^{pr2}$