#BLACKLIST PROFILE CREATION COMMAND
@bot.command(pass_context=True)
async def blacklist(ctx, removeoradd, user: discord.Member, *, reason):
if ctx.message.author.id == developerID:
if removeoradd == "add":
case_id = "BL-" + id_generator(10, "1234567890")
blacklist_template = "{\"" + user.id + "\": {\"userid\": \"" + user.id + "\", \"reason\": \"" + reason + "\", \"banned_by\": \"" + ctx.message.author.id + "\", \"case_id\": \"" + case_id + "\", \"active\": \"True\"}}"
# with open("C:/Blacklisted/{}.json".format(ctx.message.author.id), "w") as json_file:
# json.dump(blacklist_template, json_file)
blacklist = open(os.path.expanduser("~/Blacklisted/{}.json".format(ctx.message.author.id)), "x")
blacklist.write("{}".format(blacklist_template))
blacklist.close()
embed = discord.Embed(title="Admin Control", description="Blacklisted:\n``{}/{}``".format(user.name, user.id))
embed.add_field(name="Reason", value=reason)
embed.add_field(name="Case ID", value=case_id)
embed.set_footer(text="v" + version + " | " + localtime)
await bot.say(embed=embed)
embed = discord.Embed(title="You can no longer create a profile.", description="If you think this is a mistake do {}appeal <reason>".format(prefix))
embed.add_field(name="Reason", value=reason)
embed.add_field(name="Case ID", value=case_id)
embed.set_footer(text="v" + version + " | " + localtime)
await bot.send_message(ctx.message.author, embed=embed)
elif removeoradd == "remove":
pass
else:
embed=discord.Embed(title="An error occured", description="Invalid argument.\nInsert ``add`` or ``remove``.", color=0xc20000)
await bot.say(embed=embed)
else:
embed=discord.Embed(title="An error occured", description="No permission.\nYou need to be a verified developer to do this.", color=0xc20000)
await bot.say(embed=embed)
File "run.py", line 126, in blacklist
blacklist = open(os.path.expanduser("/Blacklisted/{}.json".format(ctx.message.author.id)), "x")
FileNotFoundError: [Errno 2] No such file or directory: '/Blacklisted/182288858782629888.json'
所以基本上我试图用blacklist_template内容创建一个文件。我认为当你使用&#34; w&#34;模式,它为您创建一个新文件。我做错了什么?