Answer the question
In order to leave comments, you need to log in
How to fix else error?
I recently started writing an economic bot, but when I run it, it gives me this error:
File "/storage/emulated/0/bot/bot.py", line 28
else:
^
SyntaxError: invalid syntax
import discord
from discord.ext import commands
import sqlite3
from config import settings
client = commands.Bot(command_prefix = settings['PREFIX'])
client.remove_command('help')
connection = sqlite3.connect('server.db')
cursor = connection.cursor()
@client.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
name TEXT,
id INT,
cash BIGINT,
rep INT,
lvl INT
)""")
for guild in client.guilds:
for member in guild.members:
if cursor.execute(f"SELECT id FROM users WHERE id = {member.id}").fetchone() is None:
cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 0, 0, 1)")
else:
pass
connection.commit()
print('Bot connected')
@client.event
async def on_member_join(member):
if cursor.execute(f"SELECT id FROM users WHERE id = {member.id}").fetchone() is None:
cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 0, 0, 1)")
connection.commit()
else:
pass
@client.command(aliases = ['balance', 'cash'])
async def __balance(ctx, member: discord.Member = None):
if member is None:
await ctx.send(embed=discord.Embed(
description = f"""Баланс пользователя **{ctx.author}:** **{cursor.execute("SELECT cash FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]}:leaves:**"""
))
else:
await ctx.send(embed=discord.Embed(
description = f"""Баланс пользователя **{ctx.author}:** **{cursor.execute("SELECT cash FROM users WHERE id = {}".format(member.id)).fetchone()[0]}:leaves:**"""
))
client.run(settings['TOKEN'])
Answer the question
In order to leave comments, you need to log in
Your tabs are wrong. fix her
async def on_member_join(member):
if cursor.execute(f"SELECT id FROM users WHERE id = {member.id}").fetchone() is None:
cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 0, 0, 1)")
connection.commit()
else:
pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question