Discord Python重写-帐户生成器 [英] Discord Python Rewrite - Account Generator
本文介绍了Discord Python重写-帐户生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用python和json创建一个不和谐的帐户生成器,我可以将其生成为gen,但是我无法使其在生成后删除该帐户,请提供帮助.
I Want to make a discord account generator using python and json, i can make it gen but i cant make it delete the account after genned, please help.
代码:
@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生成时,它会发送此错误:
but when i tried to gen (with the alts.pop) it sends this error:
命令引发异常:TypeError:列表"对象不能为解释为整数
Command raised an exception: TypeError: 'list' object cannot be interpreted as an integer
推荐答案
Alts只是alt的列表,它不是列表(整数)的索引,为此您必须执行以下操作:
Alts is just the list of alts, it's not an index of the list (integer) for this you would have to do something like:
@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!")
这篇关于Discord Python重写-帐户生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文