[ad_1]
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)
I'm adding values to the JSON object by using .append()
but I'm not sure what would be the proper way to remove a value from the array by value.
This is what the JSON file looks like:
"blacklist": [225915965769121792, 272445925845106700]
[ad_2]
لینک منبع