Discord.py没有这样的文件或目录,即使它确实存在

2024-06-07 23:06:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用一个脚本从一个文件加载我的机器人令牌,它在今年早些时候起作用,我最近从笔记本电脑切换到PC,并传输了我所有的文件,现在我收到了这个错误

Traceback (most recent call last):
  File "C:\Users\Meeracoat\Documents\!Discord\Discord Bots\Bacon Butler\launcher.py", line 5, in <module>
    bot.run(VERSION)
  File "C:\Users\Meeracoat\Documents\!Discord\Discord Bots\Bacon Butler\lib\bot\__init__.py", line 88, in run
    with open("./lib/bot/token.0", "r", encoding="utf-8") as tf:
FileNotFoundError: [Errno 2] No such file or directory: './lib/bot/token.0'

这是代码

def run(self, version):
        self.VERSION = version

        print("running setup...")
        self.setup()

        with open("./lib/bot/token.0", "r", encoding="utf-8") as tf:
            self.TOKEN = tf.read()

        print("running bot...")
        super().run(self.TOKEN, reconnect=True)

如您所见,该文件存在于给定的目录中

enter image description here


Tags: 文件runpyselflibtfbotusers
1条回答
网友
1楼 · 发布于 2024-06-07 23:06:30

您没有传递正确的路径,文件名不是token.0,它的名称是token.0.txt

with open("./lib/bot/token.0.txt", "r", encoding="utf-8") as tf:
    self.TOKEN = tf.read()

相关问题 更多 >

    热门问题