久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='ftzhI'><style id='ftzhI'><dir id='ftzhI'><q id='ftzhI'></q></dir></style></legend>
    1. <i id='ftzhI'><tr id='ftzhI'><dt id='ftzhI'><q id='ftzhI'><span id='ftzhI'><b id='ftzhI'><form id='ftzhI'><ins id='ftzhI'></ins><ul id='ftzhI'></ul><sub id='ftzhI'></sub></form><legend id='ftzhI'></legend><bdo id='ftzhI'><pre id='ftzhI'><center id='ftzhI'></center></pre></bdo></b><th id='ftzhI'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ftzhI'><tfoot id='ftzhI'></tfoot><dl id='ftzhI'><fieldset id='ftzhI'></fieldset></dl></div>

        <small id='ftzhI'></small><noframes id='ftzhI'>

        • <bdo id='ftzhI'></bdo><ul id='ftzhI'></ul>
        <tfoot id='ftzhI'></tfoot>

      1. Discord money bot 將用戶 ID 保存在 json 文件中.當 B

        Discord money bot keeping user ID#39;s in json file. When Bot restarts it creats a new (but same) ID for everyone(Discord money bot 將用戶 ID 保存在 json 文件中.當 Bot 重新啟動時,它會為每個人創(chuàng)建一個新的(但相同的

      2. <tfoot id='PDvfu'></tfoot>
          <legend id='PDvfu'><style id='PDvfu'><dir id='PDvfu'><q id='PDvfu'></q></dir></style></legend>
          <i id='PDvfu'><tr id='PDvfu'><dt id='PDvfu'><q id='PDvfu'><span id='PDvfu'><b id='PDvfu'><form id='PDvfu'><ins id='PDvfu'></ins><ul id='PDvfu'></ul><sub id='PDvfu'></sub></form><legend id='PDvfu'></legend><bdo id='PDvfu'><pre id='PDvfu'><center id='PDvfu'></center></pre></bdo></b><th id='PDvfu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PDvfu'><tfoot id='PDvfu'></tfoot><dl id='PDvfu'><fieldset id='PDvfu'></fieldset></dl></div>

            <small id='PDvfu'></small><noframes id='PDvfu'>

              <tbody id='PDvfu'></tbody>

              • <bdo id='PDvfu'></bdo><ul id='PDvfu'></ul>
                  本文介紹了Discord money bot 將用戶 ID 保存在 json 文件中.當 Bot 重新啟動時,它會為每個人創(chuàng)建一個新的(但相同的)ID的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  當這段代碼運行時,它可以從 discord 中獲取用戶 ID,并將他們有 100 錢放入 json,但是一旦你重新啟動機器人,你必須再次注冊,它會在 json 文件中寫入相同的用戶 ID,認為這是一個如果不是新用戶.

                  When this code runs it works getting the user ID from discord and putting they have 100 money in the json, but once you restart the bot you have to register again and it writes the same user ID in the json file thinking it's a new user when it is not.

                  from discord.ext import commands
                  import discord
                  import json
                  
                  bot = commands.Bot('!')
                  
                  amounts = {}
                  
                  @bot.event
                  async def on_ready():
                      global amounts
                      try:
                          with open('amounts.json') as f:
                              amounts = json.load(f)
                      except FileNotFoundError:
                          print("Could not load amounts.json")
                          amounts = {}
                  
                  @bot.command(pass_context=True)
                  async def balance(ctx):
                      id = ctx.message.author.id
                      if id in amounts:
                          await ctx.send("You have {} in the bank".format(amounts[id]))
                      else:
                          await ctx.send("You do not have an account")
                  
                  @bot.command(pass_context=True)
                  async def register(ctx):
                      id = ctx.message.author.id
                      if id not in amounts:
                          amounts[id] = 100
                          await ctx.send("You are now registered")
                          _save()
                      else:
                          await ctx.send("You already have an account")
                  
                  @bot.command(pass_context=True)
                  async def transfer(ctx, amount: int, other: discord.Member):
                      primary_id = ctx.message.author.id
                      other_id = other.id
                      if primary_id not in amounts:
                          await ctx.send("You do not have an account")
                      elif other_id not in amounts:
                          await ctx.send("The other party does not have an account")
                      elif amounts[primary_id] < amount:
                          await ctx.send("You cannot afford this transaction")
                      else:
                          amounts[primary_id] -= amount
                          amounts[other_id] += amount
                          await ctx.send("Transaction complete")
                      _save()
                  
                  def _save():
                      with open('amounts.json', 'w+') as f:
                          json.dump(amounts, f)
                  
                  @bot.command()
                  async def save():
                      _save()
                  
                  bot.run("Token")
                  

                  機器人關閉并重新打開并注冊兩次后的 JSON(假用戶 ID):

                  JSON after the bot is turned off and back on and registered twice (fake user IDs):

                  {"56789045678956789": 100, "56789045678956789": 100}
                  

                  即使在機器人關閉并重新打開后也需要它能夠識別用戶 ID.

                  Need it to be able to recognize the user IDs even after the bot is turned off and back on.

                  推薦答案

                  發(fā)生這種情況是因為 JSON 對象總是有鍵"的字符串.所以 json.dump 將整數(shù)鍵轉(zhuǎn)換為字符串.您可以通過在使用用戶 ID 之前將其轉(zhuǎn)換為字符串來執(zhí)行相同的操作.

                  This is happening because JSON objects always have strings for the "keys". So json.dump converts the integer keys to strings. You can do the same by converting the user ids to strings before you use them.

                  from discord.ext import commands
                  import discord
                  import json
                  
                  bot = commands.Bot('!')
                  
                  amounts = {}
                  
                  @bot.event
                  async def on_ready():
                      global amounts
                      try:
                          with open('amounts.json') as f:
                              amounts = json.load(f)
                      except FileNotFoundError:
                          print("Could not load amounts.json")
                          amounts = {}
                  
                  @bot.command(pass_context=True)
                  async def balance(ctx):
                      id = str(ctx.message.author.id)
                      if id in amounts:
                          await ctx.send("You have {} in the bank".format(amounts[id]))
                      else:
                          await ctx.send("You do not have an account")
                  
                  @bot.command(pass_context=True)
                  async def register(ctx):
                      id = str(ctx.message.author.id)
                      if id not in amounts:
                          amounts[id] = 100
                          await ctx.send("You are now registered")
                          _save()
                      else:
                          await ctx.send("You already have an account")
                  
                  @bot.command(pass_context=True)
                  async def transfer(ctx, amount: int, other: discord.Member):
                      primary_id = str(ctx.message.author.id)
                      other_id = str(other.id)
                      if primary_id not in amounts:
                          await ctx.send("You do not have an account")
                      elif other_id not in amounts:
                          await ctx.send("The other party does not have an account")
                      elif amounts[primary_id] < amount:
                          await ctx.send("You cannot afford this transaction")
                      else:
                          amounts[primary_id] -= amount
                          amounts[other_id] += amount
                          await ctx.send("Transaction complete")
                      _save()
                  
                  def _save():
                      with open('amounts.json', 'w+') as f:
                          json.dump(amounts, f)
                  
                  @bot.command()
                  async def save():
                      _save()
                  
                  bot.run("Token")
                  

                  這篇關于Discord money bot 將用戶 ID 保存在 json 文件中.當 Bot 重新啟動時,它會為每個人創(chuàng)建一個新的(但相同的)ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                    <tbody id='VmG5f'></tbody>
                  <i id='VmG5f'><tr id='VmG5f'><dt id='VmG5f'><q id='VmG5f'><span id='VmG5f'><b id='VmG5f'><form id='VmG5f'><ins id='VmG5f'></ins><ul id='VmG5f'></ul><sub id='VmG5f'></sub></form><legend id='VmG5f'></legend><bdo id='VmG5f'><pre id='VmG5f'><center id='VmG5f'></center></pre></bdo></b><th id='VmG5f'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VmG5f'><tfoot id='VmG5f'></tfoot><dl id='VmG5f'><fieldset id='VmG5f'></fieldset></dl></div>

                    <bdo id='VmG5f'></bdo><ul id='VmG5f'></ul>
                    <legend id='VmG5f'><style id='VmG5f'><dir id='VmG5f'><q id='VmG5f'></q></dir></style></legend>

                      • <tfoot id='VmG5f'></tfoot>

                            <small id='VmG5f'></small><noframes id='VmG5f'>

                          • 主站蜘蛛池模板: 综合网伊人 | 天天搞天天操 | 国产精品欧美一区二区三区 | 色视频在线免费观看 | 久久99深爱久久99精品 | 精品国产一区二区三区久久久久久 | 成人免费看片 | 日韩一区和二区 | 日本三级日产三级国产三级 | 精精国产xxxx视频在线 | 综合一区 | 一级视频黄色 | 日韩高清中文字幕 | 操久久 | 日韩不卡在线 | 91麻豆精品国产91久久久久久久久 | jizz在线看片| 亚洲国产成人精品女人久久久 | 国产98色在线 | 日韩 | 亚洲国产成人精品女人久久久 | 久久99深爱久久99精品 | 精品国产一区二区三区久久 | 噜噜噜噜狠狠狠7777视频 | 久久精品免费观看 | 亚洲欧美激情四射 | 国产丝袜一区二区三区免费视频 | 免费黄色成人 | 免费久久精品视频 | 日韩av成人 | 天天综合网91 | 久久精品网 | 一区二区视频在线 | 国产精品一区二区在线免费观看 | 亚洲黄色高清视频 | 人人干视频在线 | 欧美不卡 | 日韩av在线一区 | 久久精品视频一区二区 | 欧洲高清转码区一二区 | 精品久久中文 | 99国产精品久久久 |