Skip to content Skip to sidebar Skip to footer

Adding A Check Issue

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 will first return a message asking the u

Solution 1:

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 importSequencedefmake_sequence(seq):
    if seq isNone:
        return ()
    ifisinstance(seq, Sequence) andnotisinstance(seq, str):
        return seq
    else:
        return (seq,)

defmessage_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)
    defcheck(message):
        if ignore_bot and message.author.bot:
            returnFalseif channel and message.channel notin channel:
            returnFalseif author and message.author notin author:
            returnFalse
        actual_content = message.content.lower() if lower else message.content
        if content and actual_content notin content:
            returnFalsereturnTruereturn 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)

Post a Comment for "Adding A Check Issue"