我正在构建一个不和谐的机器人,该机器人会打出反人类的牌。问题是,当我尝试加载JSON文件时,该程序无法正常工作。
`@bot.command(pass_context=True)
async def loadCards(ctx):
with open('wcards.json') as f:
wtcards = json.load(f)
with open('bcards.json') as f:
bkcards = json.load(f)
if len(wtcards) > 1 and len(bkcards) > 1:
await ctx.send('Cards Loaded')`
我相信您在使用open()时需要使用读写参数。例如
@bot.command(pass_context=True)
async def loadCards(ctx):
with open('wcards.json', 'r') as f:
wtcards = json.load(f)
with open('bcards.json', 'r') as f:
bkcards = json.load(f)
if len(wtcards) > 1 and len(bkcards) > 1:
await ctx.send('Cards Loaded')