D
D
dayneko20032020-06-09 00:59:42
Python
dayneko2003, 2020-06-09 00:59:42

The bot works but gives an error local variable 'boolean' referenced before assignment, what should I do?

The thing is, I write my bot in python when I enter "A bundle of papers" it displays such an error 'local variable 'boolean' referenced before assignment' please help me I will be very grateful!

Code:

import config
import asyncio
import logging

from aiogram import Bot, Dispatcher, executor, types
from aiogram.dispatcher.filters import Text

logging.basicConfig(level=logging.INFO)

bot = Bot(token = config.TOKEN)
dp = Dispatcher( bot)
global boolean

@dp.message_handler(Text("Bundle of papers"))

async def echo(message: types.Message):
if boolean:
boolean = 0
await message.answer('SCP-001 is a simple stack of papers stapled together in the upper left corner.\n The top sheet is a cover labeled "Special Object Confidential Report - Confidential".\n The number of remaining sheets fluctuates between three and thirty.\n The report is not signed, its origin is unknown.')
else:
await message.answer('SCP not found in database')
@dp.message_handler()
async def echo(message: types.Message) :

if message.text == 'SCP 001':
await message.answer('Select the file you are interested in\n 1-Bundle of Papers\n 2-Prototype\n 3-Gate Guard\n 4-Castle\n 5-Factory\n 6-Circular Path\n 7-Database\ n 8 Foundation\n 9-Thirty Six\n 10-Ouroboros\n 11-Record\n 12-Past and Future\n 13-Consensus\n 14-God's Blind Spot\n 15-Dead People\n 16-And the World dressed up in beauty\n 17-Scarlet King\n 18-Simple Toymaker')
boolean = 1
else:
await message.answer('SCP not found in database')

if __name__ == '__main__':
executor.start_polling(dp , skip_updates=True)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Vasilyev, 2020-06-09
@mickvav

Replace
global boolean
with
global boolean=True

D
dayneko2003, 2020-06-09
@dayneko2003

Nope writes invalid syntax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question