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!")
添加回答
舉報