Python не видит переменные

Я делаю бота в Discord (ну тип self bot) и python не видит переменную ignore_commands но пишет что она не существует когда в коде прописано её существование

ignore_commands = False

client = commands.Bot(["self ", "Self "], self_bot = True)

@client.command()
async def off(ctx):
    if not ignore_commands: return
    
    ignore_commands = False

client.run(" Token ", bot = False)

Консоль:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnboundLocalError: local varible 'ignore_commands' referenced before assigmemt

Ответы (1 шт):

Автор решения: RAINGM

Сделайте переменную глобальной:

ignore_commands = False

client = commands.Bot(["self ", "Self "], self_bot = True)

@client.command()
async def off(ctx):
    global ignore_commands
    if not ignore_commands: return
    
    ignore_commands = False

client.run(" Token ", bot = False)

Селф боты запрещены TOS

→ Ссылка