python - Discord Python 重写 - 帐户生成器
问题描述
我想用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)时,它会发送此错误:
命令引发异常:TypeError:“列表”对象不能解释为整数
解决方案
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!")
推荐阅读
- r - mclapply 警告:计划的核心......没有交付结果,所有作业的值都会受到影响
- python - Dedupe python - '记录不符合数据模型'
- eclipse - 在通过缩放会议进行远程控制时,是否需要进行任何设置来控制 Eclipse IDE?
- android - React NativeModule 中 Android MediaPlayer 的上下文
- android - 密钥对 RSA 安卓
- python - Replace a word or set of letters from a string in a dataframe only if the string starts with that word
- azure - Kusto 如何使用带时间跨度的比较运算符
- python - 如何从这个熊猫数据框中制作四倍条形图?
- ssl - 为什么 Tomcat 9 为单独配置的两个不同域提供相同的 SSL 证书?
- sql - 当 SQL Server 总计出现在第一行而不是表末尾时出错