Deydarion
@Deydarion

Как исправить ошибку «'NoneType' object is not subscriptable»?

Вот код:

import discord
from discord.ext import commands
import json

import sqlite3

intents = discord.Intents.default()
intents.message_content = True

bot = commands.Bot(command_prefix='t.', intents=intents)
bot.remove_command('help')

connection = sqlite3.connect('server.db')
cursor = connection.cursor()

@bot.event
async def on_ready():
    cursor.execute("""CREATE TABLE IF NOT EXISTS users (
        name TXT,
        id INT,
        cash BIGINT,
        rep INT,
        lvl INT
    )""")


    for guild in bot.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()
@bot.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


file = open('token.json', 'r')
config = json.load(file)

@bot.command(name='ping')
async def ping(ctx):
    await ctx.send(f'{ctx.author.mention}pong')

@bot.command(aliases = ['balance','cash'])
async def bank(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 = {0}".format(ctx.author.id)).fetchone()[0]}**"""
        ))
    else:
        await ctx.send(embed = discord.Embed(
            description = f"""Баланс  **{member}** составляет  **{cursor.execute("SELECT cash FROM users WHERE id = {0}".format(member.id)).fetchone()[0]}**"""
        ))


bot.run(config['token'])

Когда пытаюсь вызвать команду t.balance, появляется ошибка:

File "Z:/server/chill.py", line 55, in bank
    description = f"""Бомж **{ctx.author}** баланс врего **{cursor.execute("SELECT cash FROM users WHERE id = {0}".format(ctx.author.id)).fetchone()[0]}**"""
TypeError: 'NoneType' object is not subscriptable

Как исправить?
  • Вопрос задан
  • 109 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы