Answer the question
In order to leave comments, you need to log in
What is the cause of the error "SyntaxError: expected 'else' after 'if' expression", and how to fix it?
Hello everyone, I'm writing a bot, but I don't know Python very well. Tell me what's the matter?
import discord
from discord.ext import commands
import sqlite3
import config
from config import settings
client = commands.Bot(command_prefix = settings['PREFIX'])
client.remove_command('help')
connection = sqlite3.connect('server.db')
cursor = connection.cursor()
@client.command()
async def cash(ctx, member: discord.Member = None):
if member is None:
await ctx.send(embed = discord.Embed(
score_row = cursor.execute("SELECT cash FROM users WHERE id = {}", (ctx.author.id,)).fetchone()
if score_row is not None # ошибка тут
description = f"""У тебя , **{ctx.author}** вот столько балов!**{score} :polegar_para_cima:**"""
else:
# что делать, если такого юзера еще нет в базе?
cursor.execute("INSERT INTO users (id, cash) VALUES (?, 0)", (ctx.author.id,) ) # можно его добавить
description = f"""У тебя , **{ctx.author}** пока нет ничего! Но скоро будет!"""
))
else:
await ctx.send(embed = discord.Embed(
score = cursor.execute("SELECT cash FROM users WHERE id = ?".format(member.id)).fetchone()
description = f"""У тебя , **{member}** вот столько балов!**{score} :polegar_para_cima:**"""
))
client.run(settings['TOKEN'])
File "C:\Python\bot.py", line 48
score_row = cursor.execute("SELECT cash FROM users WHERE id = {}", (ctx.author.id,)).fetchone()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: expected 'else' after 'if' expression
Answer the question
In order to leave comments, you need to log in
You forgot the colon on line 48, after is None
PS:
But I don't know much about Python. Tell me what's the matter?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question