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

        <bdo id='Mla8v'></bdo><ul id='Mla8v'></ul>

    1. <tfoot id='Mla8v'></tfoot>
      1. <small id='Mla8v'></small><noframes id='Mla8v'>

        Discord Bot - “属性错误:‘NoneType’对象没有属性‘

        时间:2023-10-11
          <tfoot id='JNS9F'></tfoot>

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

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

                    <tbody id='JNS9F'></tbody>

                  本文介绍了Discord Bot - “属性错误:‘NoneType’对象没有属性‘strip’.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我是一名新程序员,我一直在关注一个tutorial 关于如何使用下面的代码创建一个不和谐的机器人,这些代码实际上是直接从教程中复制出来的,我已经创建了一个 .env 文件来存储我的 AuthToken.每次我运行代码时,都会出现上述代码下方的错误.有小费吗?提前致谢!

                  I'm a new coder, and I've been following atutorial on how to create a discord bot with the code below having been virtually copied the code straight out from the tutorial, and I've create a .env file to store my AuthToken. Every time I run the code, I get error below aforementioned code. Any tips? Thanks in advance!

                  代码:

                  import os 
                  
                  import discord
                  
                  from dotenv import load_dotenv
                  
                  load_dotenv()
                  TOKEN = os.getenv('DISCORD_TOKEN')
                  
                  client = discord.Client()
                  
                  @client.event
                  async def on_ready():
                      print(f'{client.user} has connected to Discord!')
                  client.run(TOKEN)
                  
                  

                  错误:

                  Traceback (most recent call last):   File "/Users/XXXXXXXXXXXX/scratch/discordbot/app.py", line 16, in <module>
                      client.run(TOKEN)   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py", line 640, in run
                      return future.result()   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py", line 621, in runner
                      await self.start(*args, **kwargs)   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py", line 584, in start
                      await self.login(*args, bot=bot)   File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/discord/client.py", line 442, in login
                      await self.http.static_login(token.strip(), bot=bot) AttributeError: 'NoneType' object has no attribute 'strip' 
                  
                  

                  推荐答案

                  我按照同样的教程,遇到了同样的错误.对我来说,问题是我创建了.env".文件不正确.在教程中它说在与 bot.py 相同的目录中创建一个名为 .env 的文件:"- 这是我的问题.如果您创建一个新的文本文档,粘贴代码,然后使用名称.env"保存它,您将实际创建一个名为.env.txt"的文本文件;.

                  I was following the same tutorial and ran into the same error. Issue for me was that I had created the ".env" file incorrectly. In the tutorial it says "Create a file named .env in the same directory as bot.py:" - this was my issue. If you create a new text document, paste in the code, then save it with the name ".env", what you'll actaully be creating is a text file called ".env.txt".

                  要解决这个问题,请转到保存 Python 脚本的目录(对我来说,这是 C:ThonnyDiscordBots),然后右键单击该文件夹并选择新建".文本文档".不要更改文件名,只需将其保留为新建文本文档"即可.打开此文件(应在记事本中打开),然后粘贴教程中的代码(另外,请记住将您的机器人的实际令牌替换为名为 {your-bot-token} 的占位符变量).现在,转到文件"另存为"并在文件名字段中,输入.env";就像教程说的那样;在您点击保存之前,还请单击 另存为类型 下拉菜单(应该在 文件名 的正下方),而不是将其保留为默认类型(*.txt),将其更改为所有文件".

                  To get around this, go to the directory where you have the python script saved (for me this is C:ThonnyDiscordBots), then right-click in that folder and select "New > Text Document". Don't change the filename yet, just leave it as "New Text Document". Open this file (should open in Notepad), then paste in the code from the tutorial (also, remember to substitute your bot's actual token in for the placeholder variable called {your-bot-token}). Now, go to "File > Save As" and in the File Name field, type ".env" just like the tutorial says to; BEFORE you hit save, also click the Save as type dropdown (should be right below File Name) and instead of leaving it as the default type (*.txt), change this to "All Files".

                  如果您已正确完成此操作,您应该会看到您的.env".文件资源管理器中的文件,以及类型"列现在将显示ENV 文件";而不是文本文档".尝试再次运行代码.

                  If you've done this correctly, you should see your ".env" file in file explorer, and the "Type" column will now show "ENV File" instead of "text document". Try to run the code again.

                  这对我有帮助.我的理解是load_dotenv()";正在寻找 ENV type 的文件,而不仅仅是 any 名为.env"的文件;(任何类型).只要此文件与您正在运行的脚本位于同一目录中,它就应该可以工作.

                  This is what helped me. My understanding is that "load_dotenv()" is looking for a file of the ENV type, not just any document called ".env" (of any type). As long as this file is placed in the same directory as the script you're running, it should work.

                  这篇关于Discord Bot - “属性错误:‘NoneType’对象没有属性‘strip’.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:传递了不正确的令牌 下一篇:Discord.py - 如何检测用户是否提到/ping 机器人

                  相关文章

                  最新文章

                  <legend id='hYVFE'><style id='hYVFE'><dir id='hYVFE'><q id='hYVFE'></q></dir></style></legend>

                    <bdo id='hYVFE'></bdo><ul id='hYVFE'></ul>

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

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