-2
@echo off
:a
title DISCORD.PY BOT RUNNER
cls
color 0a
python bot.py

if errorlevel == 1 (
    color 4
    echo.
    echo ERROR
    echo.
    echo [1] CLOSE : [2] RESTART

    set /p error = ""

    if %error% == 1 exit
    if %error% == 2 goto a
)

echo BOT IS CLOSED
echo.
echo [1] CLOSE

set /p closed = ""

if %closed% == 1 exit

Can anyone say me whats wrong with this script? I see there are nothing wrong. Bc i want to make an discord.py bot starter.

  • The errorlevel you're currently working with is that between `python.exe` and `cmd.exe`, but I'd assume that you want the exit/error code between `bot.py` and `python.exe` instead. If that assumption is correct, then the content of `bot.py` may be what requires modification, and you haven't posted any of that. As for what is wrong with your batch script, not only should `if errorlevel == 1 (` be changed to `if not errorlevel 0 (`, and if you're not going to use `choice.exe`, you'll need delayed expansion with `set /p`, as you are both defining and using a variable within a parenthesized block. – Compo Feb 27 '22 at 12:25

1 Answers1

0

errorlevel == 1 - the string errorlevel will never be the same as the string 1. You need the value of errorlevel, that is %errorlevel%.

Since you are setting the value of error within a parenthesised sequence of statements (ie. a block) then batch will evaluate the entire statement from the if to the closing parenthesis, and substitute for each %variable% with the valu of that variable at the time the statement was parsed, that is, before it is executed. You are changing the value of error within the block, so you need to extract its run-time value for testing and thus you need to invoke delayedexpansion. Please see https://stackoverflow.com/a/30284028/2128947

ALSO : set /p variable = will establish a variable named variableSpace not variable. The space before the = is significant.

Magoo
  • 77,302
  • 8
  • 62
  • 84