def input_number(ctx: commands.Context,
message: str="Please enter a number within 10 seconds.",
*, timeout: int=10, min_value: int=None, max_value: int=None):
"""Input number helper. Ask a confirmation message with a timeout of 10 seconds.
ctx - The context in which the question is being asked.
message - Optional messsage that the question should ask.
timeout - Timeout, in seconds, before automatically failing.
min_value - Minimum accepted value for the input.
max_value - Maximum accepted value for the input.
"""
await ctx.send(message)
def check(message):
"""A checking function dynamically to verify input."""
if message.author != ctx.message.author or not message.clean_content.isdecimal():
return False
number = int(message.clean_content)
if (min_value and number < min_value) or (max_value and number > max_value):
return False
return True
try:
message = await ctx.bot.wait_for("message", timeout=timeout, check=check)
except asyncio.TimeoutError:
raise commands.UserInputError("Timed out waiting.")
return int(message.clean_content)
评论列表
文章目录