A
A
Andrew2021-08-12 02:44:05
Python
Andrew, 2021-08-12 02:44:05

How to expect a random number input?

I have a python script, it asks to enter some message, after that it asks to enter a number in the range from 1 to 139, how can I get this number? discord.py library

if message.content == '!Databook':
        channel = message.channel
        await channel.send('Введите номер датабука (1-4)')
        await channel.send('В таком формате: "Датабук 1" вместо 1 номер датабука')

        def check(m):
        	return m.content == 'Датабук 1' and m.channel == channel

        msg = await bot.wait_for('message', check=check)
        await channel.send('Введите страницу (1-139)'.format(msg))

        def check_two(m):
        	return m.content == # Вот тут надо получить число которое вводит пользователь(оно из диапазона 1-139)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-08-12
@AndreyJoestar

def check_two(m):
    m = m.content
    return m.isdigit() and (1 <= int(m) <= 139)

This function will return True if it receives a string containing only digits and these digits can be converted to an integer in the specified range.
Frankly, I really don’t like the approach itself with such a function, tk. you have to hardcode values ​​there, or pass them there through global variables, or even more complex approaches with composing child classes, and even with async ... well, okay, so be it for now.
Next, you need to apply the function in the parameter of the wait_for method
def check_two(m):
    m = m.content
    return m.isdigit() and (1 <= int(m) <= 139)

DataBook_Page = await client.wait_for('message', check=check_two)
well and so on

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question