【发布时间】:2021-06-19 16:31:02
【问题描述】:
我正在尝试导入我的主要 python 文件,但它不起作用。
import discord
from discord.ext import commands
from ..bot import bot
class help(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command(name="help", aliases=["Help"])
async def help(self,context, message = None):
embed = discord.Embed(title="Help command")
cmds = ""
if message == None:
bot.listcom(cmds)
embed.add_field(name="Commands", value=cmds)
if not message == None:
pass
await context.send(embed=embed)
def setup(client):
client.add_cog(help(client))
终端输出:
ImportError: attempted relative import with no known parent package
我尝试使用 import ..bot 但它给出了语法错误,当我尝试仅使用 import bot 时它说它不存在。有人可以帮帮我吗?
【问题讨论】:
-
相对导入仅适用于包内的子模块。如果您显示您的文件夹结构可能会有所帮助。
标签: python-3.x discord.py