Reputation: 11
i want to make a blacklist system for my discord.py bot in async... i want to use a json rather then a database im just really confused atm
@client.command()
async def blacklist(ctx, member: discord.Member = None):
with open('blacklist.json', 'r')as f:
users = json.load(f)
if user.id in users:
await client.say("already blacklisted")
else:
with open('blacklist.json', 'w')as f:
json.dump(users, f)
if not user.id in users:
users[user.id] = {}
await client.say(f"done!! {member.name} has been blacklisted")```
Upvotes: 1
Views: 1124
Reputation: 1
@client.command()
async def blacklist(ctx, member: discord.Member = None):
with open('blacklist.json', 'r') as f:
users = json.load(f)
if user.id in users:
await client.say("already blacklisted")
else:
with open('blacklist.json', 'w') as f:
json.dump(users, f)
if not user.id in users:
users[user.id] = {}
await client.say(f"done!! {member.name} has been blacklisted")
Upvotes: 0
Reputation: 1812
If blacklist.json
is a list, you can do:
@client.command()
async def blacklist(ctx, member: discord.Member = None):
if not member:
return
with open('blacklist.json', 'r+') as f:
users = json.load(f)
if member.id in users:
await client.say("already blacklisted")
return
users.append(member.id)
f.seek(0)
json.dump(users, f)
f.truncate()
await client.say(f"done!! {member.mention} has been blacklisted")
Upvotes: 1