Adding a check issue

前端 未结 1 1278
暗喜
暗喜 2020-12-11 13:34

Hi I\'m trying to check if only the specific user has typed yes or no then apply the role.

At the moment if a mentionable role is added it wil

相关标签:
1条回答
  • 2020-12-11 13:59

    I have some code I use to produce check functions for wait_for. Below is what I use for waiting for messages

    from collections.abc import Sequence
    
    def make_sequence(seq):
        if seq is None:
            return ()
        if isinstance(seq, Sequence) and not isinstance(seq, str):
            return seq
        else:
            return (seq,)
    
    def message_check(channel=None, author=None, content=None, ignore_bot=True, lower=True):
        channel = make_sequence(channel)
        author = make_sequence(author)
        content = make_sequence(content)
        if lower:
            content = tuple(c.lower() for c in content)
        def check(message):
            if ignore_bot and message.author.bot:
                return False
            if channel and message.channel not in channel:
                return False
            if author and message.author not in author:
                return False
            actual_content = message.content.lower() if lower else message.content
            if content and actual_content not in content:
                return False
            return True
        return check
    

    You can then easily pass the requirements of the message you want to receive to wait_for

    check = message_check(author=ctx.author, channel=ctx.channel, content=('y', 'yes'))
    msg = await self.bot.wait_for("message", timeout=20.0, check=check)
    
    0 讨论(0)
提交回复
热议问题