I'm writing code for my discord bot on discord.py. At one point, he began to give a "syntax invalid" error for everything, even if he hadn't done it before. The last two versions of the code and errors:
@client.command(aliases = ['balance', 'cash', 'money', 'bal', 'бал', 'баланс', 'деньги'])
async def balance(ctx, member: discord.Member = None):
if member is None:
await ctx.send(embed = discord.Embed(
title = f"""Баланс **{ctx.author}"""
description = f"""Коины: **{cursor.execute("SELECT cash FROM user WHERE id = {}").format(ctx.author.id).fetchone()[0]}** <:DS_SaphireCoin:1023242850483314710> \nОсколки Шизы:**{cursor.execute("SELECT shiza FROM user WHERE id = {}")}** <a:DS_shiza:1023239736061603864>"""
timestamp = ctx.message.created_at
))
and
@client.command(aliases = ['balance', 'cash', 'money', 'bal', 'бал', 'баланс', 'деньги'])
async def balance(ctx, member: discord.Member = None):
if member is None:
await ctx.send(embed = discord.Embed(
title = f"""Баланс **{ctx.author}"""
description = f"""Коины: **{cursor.execute("SELECT cash FROM user WHERE id = {}").format(ctx.author.id).fetchone()[0]}** <:DS_SaphireCoin:1023242850483314710>"""
timestamp = ctx.message.created_at
))
in ver 1 error is
PS D:\Jeka\Chmonya bot> d:; cd 'd:\Jeka\Chmonya bot'; & 'D:\Jeka\python\python.exe' 'c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '54767' '--' 'd:\Jeka\Chmonya bot\commands_user.py'
Traceback (most recent call last):
File "D:\Jeka\python\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\Jeka\python\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 320, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 294, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "d:\Jeka\Chmonya bot\commands_user.py", line 16
description = f"""Коины: **{cursor.execute("SELECT cash FROM user WHERE id = {}").format(ctx.author.id).fetchone()[0]}** <:DS_SaphireCoin:1023242850483314710> \nОсколки Шизы:**{cursor.execute("SELECT shiza FROM user WHERE id = {}").fetchone()[0]}** <a:DS_shiza:1023239736061603864>**"""
^
SyntaxError: invalid syntax
in ver 2
PS D:\Jeka\Chmonya bot> d:; cd 'd:\Jeka\Chmonya bot'; & 'D:\Jeka\python\python.exe' 'c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '54777' '--' 'd:\Jeka\Chmonya bot\commands_user.py'
Traceback (most recent call last):
File "D:\Jeka\python\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\Jeka\python\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
cli.main()
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 320, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "c:\Users\JeKa\.vscode\extensions\ms-python.python-2022.14.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 294, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "d:\Jeka\Chmonya bot\commands_user.py", line 16
description = f"""Коины: **{cursor.execute("SELECT cash FROM user WHERE id = {}").format(ctx.author.id).fetchone()[0]}** <:DS_SaphireCoin:1023242850483314710>"""
^
SyntaxError: invalid syntax
i dunno how to fix it, pls help
As @quamrana said in his comment, I think you're missing a comma at the end of your function arguments.
@client.command(aliases = ['balance', 'cash', 'money', 'bal', 'бал', 'баланс', 'деньги'])
async def balance(ctx, member: discord.Member = None):
if member is None:
await ctx.send(embed = discord.Embed(
title = f"""Баланс **{ctx.author}""",
description = f"""Коины: **{cursor.execute("SELECT cash FROM user WHERE id = {}").format(ctx.author.id).fetchone()[0]}** <:DS_SaphireCoin:1023242850483314710>""",
timestamp = ctx.message.created_at
))
In general, for any function, the comma syntax is as below:
#Example
def hello_world(
string = "something",
other_string = "something else",
x = 1):
print(string, other_string, x)
hello world(string = "f",
other_string = "y",
x = 2)