第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

KeyError:discord.py 中的“594750729810477063”

KeyError:discord.py 中的“594750729810477063”

幕布斯6054654 2023-10-06 13:45:20
await open_account(ctx.author)    users = await get_bank_data()    earnings = (a_var3)    users[str(discord.user.id)]["Simp Wallet"] += earnings@bot.command()async def balance(ctx):    await open_account(ctx.author)    users = await get_bank_data()    wallet_amt = users[str(user.id)]["Simp Wallet"] = 0    bank_amt =  users[str(user.id)]["Simp Bank"] = 0    em = discord.Embed(title = f"{ctx.author.name}'s Balance")    em.add_field(name = "Simp Wallet", value = wallet_amt)    em.add_field(name = "Simp Bank", value = bank_amt)    await ctx.send(embed = em)async def open_account(user):    users = await get_bank_data()    if str(user.id) is users:        return False    else:        users[str(user.id)]["Simp Wallet"] = 0        users[str(user.id)]["Simp Bank"] = 0    with open('mainbank.json',"w") as f:        json.dump(users,f)    return Trueasync def get_bank_data():    with open('mainbank.json',"r") as f:        users = json.load(f)    return usersDiscord.ext.commands.errors.CommandInvokeError:命令引發(fā)異常:KeyError:'594750729810477063'。就是這么說(shuō)的。我不是這方面的專家,所以,任何幫助將不勝感激!完整回溯如下:The above exception was the direct cause of the following exception:Traceback (most recent call last):  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke    await ctx.command.invoke(ctx)  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke    await injected(*ctx.args, **ctx.kwargs)  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped    raise CommandInvokeError(exc) from excdiscord.ext.commands.errors.CommandInvokeError: Command raised an exception: KeyError: '345878244756684801'
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻(xiàn)1835條經(jīng)驗(yàn) 獲得超7個(gè)贊

您的open_account函數(shù)看起來(lái)不會(huì)執(zhí)行您需要執(zhí)行的操作。如果還沒(méi)有給定用戶的新帳戶,您需要它來(lái)創(chuàng)建一個(gè)新帳戶。但是您沒(méi)有任何代碼來(lái)檢查現(xiàn)有用戶(看起來(lái)您正在嘗試,但有一個(gè)拼寫錯(cuò)誤),并且您也沒(méi)有代碼來(lái)創(chuàng)建內(nèi)部字典。


這就是我認(rèn)為你想要的:


async def open_account(user):

    users = await get_bank_data()


    if str(user.id) in users:                         # note, use "in" here rather than "is"

        return False


    users[str(user.id)] = {"Simp Wallet": 0, "Simp Bank": 0}  # create inner dictionary here


    with open('mainbank.json',"w") as f:

        json.dump(users,f)

    return True


查看完整回答
反對(duì) 回復(fù) 2023-10-06
  • 1 回答
  • 0 關(guān)注
  • 103 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)