I can't call function from another file. My code:
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)
Error Code:
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
Whole function is in class: embeds.definitions. (Yeah those are two classes)
And this happens with any function
When you are using return
function in the Python, you can't use it more then once in a function. return
returns a value and quits the function.
Also you can't use =
in return
too. You can change your code like this:
def standard(title, desc, color):
embed = discord.Embed(title=title, description=desc, color=color)
embed.set_footer(text=embeds.settings.footer)
return embed
This is a syntax error indeed. You are returning
an assignment
return x = y
x = y
doesn't actually hold any value, instead it puts the value y
inside of the variable x
, so you can't return
it (it does
something, but doesn't give
you anything).
I don't get why you are returning all of these things? You might wanna look into how return
works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.