trivia.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:kitsuchan-2 作者: n303p4 项目源码 文件源码
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):
    """Number input helper, with timeout.

    * 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. Defaults to 10.
    * min_value - Minimum accepted value for the input. Defaults to None.
    * max_value - Maximum accepted value for the input. Defaults to None.
    """
    await ctx.send(message)

    def check(message):
        """The check function used in bot.wait_for()."""
        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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号