If you are set on doing this with PyInputPlus, you can get the desired behavior using the parameter blockRegexes, which permits setting a custom error message (in the documentation, this is apparently wrongly documented for the non-existing parameter blocklistRegexes in PyInputPlus parameters):
blocklistRegexes (Sequence, None): A sequence of regex str or (regex_str, error_msg_str) tuples that, if matched, will explicitly fail validation.
Since it is simpler to write a regex that matches only integers than one that matches everything except them, I first used blockRegexes to forbid everything using the regex .* and then allowRegexes to add exceptions for integers using the regex ^-?\d+$' (only positive and negative integers, see https://regex101.com/r/1ymJzE/1).
The following example accepts negative or positive integers and prints a custom Spanish error message otherwise:
import pyinputplus as pyip
response = pyip.inputInt('please, enter a number: ',
allowRegexes=[r'^-?\d+$'],
blockRegexes=[(r'.*','¡Esto no es un número entero!')]
)
Execution:
please, enter a number: a
¡Esto no es un número entero!
please, enter a number: 1-2
¡Esto no es un número entero!
please, enter a number: 3.2
¡Esto no es un número entero!
please, enter a number: 5,4
¡Esto no es un número entero!
please, enter a number: -12
You could also achieve the same with only blockRegexes by providing a regex that accepts everything but integers. This regex is a bit more complex if negative numbers should be allowed. See this answer to a respective question for a detailed explanation of the regex.
This code achieves the same result as the one above:
import pyinputplus as pyip
response = pyip.inputInt('please, enter a number: ',
blockRegexes=[(r'[^-0-9]+|[0-9]+(?=-)|^-$|-{2,}','¡Esto no es un número entero!')]
)