【发布时间】:2021-01-15 04:46:21
【问题描述】:
我不能从另一个文件调用函数。 我的代码:
def standard(title, desc, color):
return color = embeds.colors. + color
return embed=discord.Embed(title=title, description=desc, color=color)
return embed.set_footer(text=embeds.settings.footer)
错误代码:
Traceback (most recent call last):
File "C:\Users\def75\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\def75\Desktop\discordbot\new\cogs\fun.py", line 22, in _8ball
await ctx.send(embed=embed)
UnboundLocalError: local variable 'embed' referenced before assignment
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\def75\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\def75\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\def75\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnboundLocalError: local variable 'embed' referenced before assignment
C:\Users\def75\Desktop\discordbot\new>python main.py
Traceback (most recent call last):
File "main.py", line 4, in <module>
from config import *
File "C:\Users\def75\Desktop\discordbot\new\config.py", line 24
return color = embeds.colors. + color
^
SyntaxError: invalid syntax
整个函数在类中:embeds.definitions。 (是的,这是两个类)
这发生在任何函数上
【问题讨论】:
-
嵌入需要在范围内。没有更多上下文,一些可能性:它必须被导入,它必须从另一个模块或实例中引用
标签: python function discord discord.py