Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.py - SyntaxError f-string: empty expression not allowed

I'm getting a SyntaxError: f-string: empty expression not allowed I'm not sure (at all) what this means

I've tried moving around the code & looked online but I've got no different results

The code is:

@client.command()
async def load(ctx, extension):
 client.load_extension(f'cogs.{extension}')

 await ctx.send(f"Loaded the {} module!".format(extension))

It's for cogs & I'm sure I've got everything else right, I'm not sure though

If anyone knows what to do then please tell me, thx

like image 245
Jakaboi Avatar asked Jun 14 '19 20:06

Jakaboi


Video Answer


2 Answers

The problem is the empty {} in the f-string. F-strings require a variable name between the braces. The line with the string should be:

await ctx.send(f"Loaded the {extension} module!")

Or

await ctx.send("Loaded the {} module!".format(extension))

Hope this helps.

like image 141
CrazySqueak Avatar answered Sep 19 '22 11:09

CrazySqueak


If you want to keep your code structure the way it is, you can also do like this:

await ctx.send(f"Loaded the {{}} module!".format(extension))
like image 26
herickmota Avatar answered Sep 19 '22 11:09

herickmota