亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Discord Python Rewrite - 帳戶生成器

Discord Python Rewrite - 帳戶生成器

aluckdog 2023-07-18 15:17:10
我想使用 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!")但是當我嘗試 gen (使用 alts.pop)時,它會發送以下錯誤:命令引發異常:TypeError:“list”對象無法解釋為整數
查看完整描述

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!")


查看完整回答
反對 回復 2023-07-18
?
MYYA

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!")


查看完整回答
反對 回復 2023-07-18
  • 2 回答
  • 0 關注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號