【发布时间】:2021-06-14 16:37:50
【问题描述】:
我有我为 discord.py 机器人制作的这个模块(虽然不是 COG)。它显然定义了函数“help_command”,但每当我尝试运行它时,都会出现上述错误。我无法理解它,所以我认为向社区询问可能是值得的。
discord_main.py
import discord
from discord.ext import commands
import gsheet
import os
import embed_storage
async def help(ctx, argument='Helping'):
await ctx.send(embed=embed_storage.help_command('stargazer', argument))
embed_storage.py
import discord
from cogs.points import points_help_dict
from discord_main import help_dictionary
import gsheet
def help_command(cog_name: str, command: str):
if cog_name == 'stargazer':
use_dict = help_dictionary
title = 'Help'
description = 'Learn how the Stargazer Bot works'
footer_message = 'Prefix for this bot is \'a\''
else:
raise UnboundLocalError(
"Yeh this part of the code should have never run.")
command = command.lower()
if command in use_dict:
title = command.title()
description = use_dict[command]
field = False
help_command_embed = discord.Embed(
title=title,
description=description,
colour=discord.Colour.from_rgb(234, 255, 208)
)
return help_command_embed
任何帮助都会令人惊叹。也很抱歉这个愚蠢的问题。只是无法解决这个愚蠢的错误。
编辑:尝试回滚到我最新的工作版本的代码以及我运行它的时间。它仍然给了我同样的错误。所以错误不在新添加的代码中
【问题讨论】:
-
看起来你们已经开始相互导入了。您能否更新您的问题以显示您的所有导入?
-
是否会两次导入相同的模块(一次在 discord_main.py 中,另一次在 embed_storage.py 中)会导致此错误?
-
Python 版本 3.8.1
-
我已经更新了答案。
-
这不起作用,Discord 自动关闭了会话。但我意识到我真的不需要
discord_main.py中的帮助字典。字典的一个简单的 Ctrl + C、Ctrl + v 解决了这个问题。非常感谢
标签: python python-3.x discord.py attributeerror