T
T
Timur Burangulov2022-03-06 15:39:34
Python
Timur Burangulov, 2022-03-06 15:39:34

Why does it display such an error and how to remove it: aiogram.utils.exceptions.BadRequest: Message must be non-empty?

-------- | | | | | | |\\



| \\
----------
""",
"""
--------
| |
|
|
|
|
|
|\\
| \\
----------
""",
"""
--------
| |
| 0
| /X\\
| / \\
|
|
|\\
| \\
----------
"""
)

words = {"LESSONS":"What can be cooked but not eaten?",
"CHESS-PLAYER":"Who walks while sitting?",
"DOOR":" Who comes, who leaves, everyone leads her by the hand.",
"
"DAY": "It dies in the evening, comes to life in the morning.", " RADIO
": "They say in Moscow, but we can hear it."
",
"TOILET":"The most popular paper",
"SECRET":"What can be shared only once?"}

logging.basicConfig(level = logging.INFO)

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

@dp.message_handler(commands=["Gallowsman"])

async def start_game(message: types.Message):

key = random.choice(list(words.keys()))
length = "-"*len(key)
wrong = 0
used = []
while wrong < len(HANGMAN) and length != key:
await message.answer(
fmt.text(
fmt.text('You used these letters:', *used),
fmt.text("Errors:", fmt.hbold(wrong)),
fmt.text('The riddle sounds like this:', words[ key]),
fmt.text('Word:', length),
sep="\n"
), parse_mode="HTML")

if message.text == key:
length = key
break

if message.text in key:
new = ""
for i in range(len(key)):
if message.text == key[i]:
new += message.text
else:
new += length[i]
length = new
else:
await message.answer(fmt.text(HANGMAN[wrong]))
wrong += 1

if length == key:
await message.answer(fmt.text("You win!!! The hidden word was:", key) )

else:
await message.answer(fmt.text('You've been hanged :('))
await message.answer(fmt.text('the hidden word was:', key))

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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Chetchasov, 2022-03-06
@TalismanChet

Most likely, there is a situation that the message being processed by the program is empty. in this case, I advise you to use the try-except construct , where, with such an error, you simply try again, after adding a space to the message (for example).
If you think this answer is correct, please tick it. Thanks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question