2 回答
TA贡献1818条经验 获得超3个赞
Alts 只是 alts 列表,它不是列表(整数)的索引,为此您必须执行以下操作:
@client.command()
async def gentest(ctx):
genembed = discord.Embed(
title="Minecraft NFA",
colour=discord.Color.green()
)
with open('alts.json', 'r') as f:
alts = json.load(f)
choice = random.choice(alts)
genembed.add_field(name="Account:", value=choice, inline=False)
with open('alts.json', 'w') as f:
del alts[alts.index(choice)]
f.write(json.dumps(alts, indent=4))
await ctx.author.send(embed=genembed)
await ctx.send(f"{ctx.author.mention} Please check your DMs!")
TA贡献1868条经验 获得超4个赞
您可以添加到 JSON 文件。我这样做是为了让用户 ID 为键,值为数字 0。您可以轻松编辑它。
这可能不是您想要的,但在我看来这样做更好。这是为用户创建一个帐户,而不是使用一定数量的帐户。
@bot.command()
async def gentest(ctx):
genembed = discord.Embed(
title="Minecraft NFA",
colour=discord.Color.green()
)
with open('accounts.json', 'r') as f:
accounts = json.load(f)
genembed.add_field(
name="Account:", value='Created Successfully', inline=False)
accounts[ctx.author.id] = 0 # key is the id of the user and value is zero
with open('accounts.json', 'w') as f:
json.dump(accounts, f)
await ctx.author.send(embed=genembed)
await ctx.send(f"{ctx.author.mention} Please check your DMs!")
添加回答
举报