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

    2. <small id='lTr99'></small><noframes id='lTr99'>

      <tfoot id='lTr99'></tfoot>

        <bdo id='lTr99'></bdo><ul id='lTr99'></ul>
    3. 我将如何为我的不和谐机器人令牌创建一个 .en

      时间:2023-09-09

          <tbody id='at6PF'></tbody>

        1. <i id='at6PF'><tr id='at6PF'><dt id='at6PF'><q id='at6PF'><span id='at6PF'><b id='at6PF'><form id='at6PF'><ins id='at6PF'></ins><ul id='at6PF'></ul><sub id='at6PF'></sub></form><legend id='at6PF'></legend><bdo id='at6PF'><pre id='at6PF'><center id='at6PF'></center></pre></bdo></b><th id='at6PF'></th></span></q></dt></tr></i><div id='at6PF'><tfoot id='at6PF'></tfoot><dl id='at6PF'><fieldset id='at6PF'></fieldset></dl></div>

        2. <small id='at6PF'></small><noframes id='at6PF'>

          <legend id='at6PF'><style id='at6PF'><dir id='at6PF'><q id='at6PF'></q></dir></style></legend>
              • <bdo id='at6PF'></bdo><ul id='at6PF'></ul>
                <tfoot id='at6PF'></tfoot>
                本文介绍了我将如何为我的不和谐机器人令牌创建一个 .env 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                所以,最近有人告诉我,仅将 Discord Bot 令牌存储在顶部的变量中是不好的做法,使用 .env 文件会更好.有人可以向我解释如何创建包含令牌的 .env 文件并将其导入到我的 bot.py 文件中吗?

                So, I was recently told that just storing the Discord Bot token in a variable at the top is bad practice and a .env file would be better. Can someone explain to me how I would create the .env file with the token in it and import it into my bot.py file?

                推荐答案

                你可以使用一个名为 python-dotenv 的库/模块,安装该库

                You can use a libary/module called python-dotenv, install the library with

                pip install python-dotenv
                

                要在您的代码中使用它,您必须导入 os 模块以及新安装的 dotenv 包

                To use it in your code, you have to import the os module as well as the freshly installed dotenv package

                import os
                from dotenv import load_dotenv
                

                在导入后代码的开头,您应该使用 load_dotenv() 来加载 .env 文件.然后就可以使用os.getenv("DOTENV variablename here")来获取文件的内容了.

                At the beginning of your code after the imports you should have load_dotenv() to load the .env file. Then you can use os.getenv("DOTENV variablename here") to get the content of the file.

                指令列表:

                1. pip install python-dotenv.
                2. 在项目的根目录中创建一个名为 .env 的文件.
                3. 写一行:DISCORD_TOKEN = 你的令牌(不需要引号)
                4. 您的代码中应该有 import os 和 from dotenv import load_dotenv.
                5. 在程序开始时调用 load_dotenv() 来加载文件.
                6. 要获取令牌,您只需执行 os.getenv("DISCORD_TOKEN").
                1. pip install python-dotenv.
                2. Create a file named .env in the root of your project.
                3. Write one line: DISCORD_TOKEN = your token (no quotes needed)
                4. you should have import os and from dotenv import load_dotenv in your code.
                5. Call load_dotenv() at the beginning of your program to load the file.
                6. To get your token, you just have to do os.getenv("DISCORD_TOKEN").

                示例代码:

                import os
                from dotenv import load_dotenv
                
                load_dotenv()
                
                TOKEN = os.getenv("DISCORD_TOKEN")
                

                dotenv 文件示例:

                Example dotenv file:

                DISCORD_TOKEN=this.is.my.token.blah.blah.blah
                

                这篇关于我将如何为我的不和谐机器人令牌创建一个 .env 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:使用本地文件作为 set_image 文件 discord.py 下一篇:AttributeError:“Bot"对象没有属性“add_roles&quo

                相关文章

                最新文章

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

                  1. <small id='hzywk'></small><noframes id='hzywk'>

                      <bdo id='hzywk'></bdo><ul id='hzywk'></ul>
                  2. <tfoot id='hzywk'></tfoot>