首页 > 解决方案 > 如何在我的 python 代码 (discord.py) 上写下 Github 导入文件夹的名称?

问题描述

我的 python bot 代码有问题,我需要 chdir 到我所有文件都在 Github 中的文件夹,但我不知道该怎么做。

我试过这个但它不起作用:

os.chdir("Game-Master /")

它在日志上给了我这个错误:

2020-11-17T20:29:12.491976+00:00 heroku[worker.1]: State changed from crashed to starting
2020-11-17T20:29:15.869590+00:00 heroku[worker.1]: Starting process with command `python main.py`
2020-11-17T20:29:16.520541+00:00 heroku[worker.1]: State changed from starting to up
2020-11-17T20:29:18.493338+00:00 app[worker.1]: Traceback (most recent call last):
2020-11-17T20:29:18.493358+00:00 app[worker.1]:   File "main.py", line 8, in <module>
2020-11-17T20:29:18.493535+00:00 app[worker.1]:     os.chdir("Game-Master /")
2020-11-17T20:29:18.493589+00:00 app[worker.1]: FileNotFoundError: [Errno 2] No such file or directory: 'Game-Master /'

这是代码的重要部分:


import os
import discord
from discord.ext import commands
import asyncio
import json
import random

os.chdir("Game-Master /")
bot = commands.Bot(command_prefix = "!", description = "organise des combats") 
token = str(os.environ.get('BOT_TOKEN'))
bot.remove_command('help')

标签: pythongithubdiscord.py

解决方案


该目录只是 . 所以我只需要写“。” 在 chdir 上

os.chdir('.')

就这些


推荐阅读