Discord Python 重写 - 帐户生成器
Discord Python Rewrite - Account Generator
我想使用 python 和 json 制作一个不和谐的帐户生成器,我可以生成但生成后无法删除帐户,请帮忙。
代码:
@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)
genembed.add_field(name="Account:", value=random.choice(alts), inline=False)
with open('alts.json', 'w') as f:
alts = alts.pop(alts)
await ctx.author.send(embed=genembed)
await ctx.send(f"{ctx.author.mention} Please check your DMs!")
但是当我尝试生成时(使用 alts.pop)它发送了这个错误:
Command raised an exception: TypeError: 'list' object cannot be
interpreted as an integer
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!")
您可以添加到 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!")
我想使用 python 和 json 制作一个不和谐的帐户生成器,我可以生成但生成后无法删除帐户,请帮忙。
代码:
@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)
genembed.add_field(name="Account:", value=random.choice(alts), inline=False)
with open('alts.json', 'w') as f:
alts = alts.pop(alts)
await ctx.author.send(embed=genembed)
await ctx.send(f"{ctx.author.mention} Please check your DMs!")
但是当我尝试生成时(使用 alts.pop)它发送了这个错误:
Command raised an exception: TypeError: 'list' object cannot be interpreted as an integer
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!")
您可以添加到 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!")