久久久久久久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 重新啟動時,它會為每個人創建一個新的(但相同的

      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 重新啟動時,它會為每個人創建一個新的(但相同的)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.

                  推薦答案

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

                  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 重新啟動時,它會為每個人創建一個新的(但相同的)ID的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  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'>

                          • 主站蜘蛛池模板: 久久国产亚洲 | 日韩免费视频一区二区 | 69电影网| 激情五月婷婷综合 | 国产一级片av | 欧美激情视频一区二区三区免费 | 精品区一区二区 | 国产探花在线观看视频 | 久久精品国产一区二区三区不卡 | 国产精品久久亚洲 | 国产精品视频一二三区 | 国产69精品久久久久777 | 国产在线精品一区二区三区 | 成人免费视频网站在线观看 | 欧美二区在线 | 国产剧情一区 | 日韩毛片中文字幕 | 欧美精品v国产精品v日韩精品 | 久久久久免费精品国产小说色大师 | 91激情视频| 日韩精品一区二区三区中文在线 | 国产精品一区二区在线播放 | 日韩在线视频一区二区三区 | 国产精品综合色区在线观看 | 亚洲精品久久久蜜桃 | av中文在线观看 | a在线免费观看视频 | 精品福利在线 | 久久国产精品视频 | 亚洲成人久久久 | 99久久精品一区二区成人 | 我想看一级黄色毛片 | 亚洲视频二区 | 午夜免费观看体验区 | 免费三级网站 | 黄色一级毛片 | 国产片淫级awww | 在线免费观看一区二区 | 亚洲乱码国产乱码精品精的特点 | 午夜免费视频 | www312aⅴ欧美在线看 |