xupaii
xupaii

Reputation: 475

discord.py rewrite | Problem with getting author message

I've been making a number game command in my server, and someone recommended I add difficulties. So, I have 3 difficulties for the user to chose from. I have already got a bit of code which got the author's response and worked, so I re-used it in my code, and now I am stumped. It may be glaringly obvious, but I cannot find it:

@client.command(name='numgame',
                brief='Guess a number between 1 and 100',
                pass_ctx=True)
async def numgame(ctx):
    if ctx.author.id != 368442355382222849:
        await ctx.send('Command currently disabled')
        return

    await ctx.send('Difficulties: a] 1-10 b] 1-50 c] 1-100')
    msg = await client.wait_for('message', check=check(ctx.author), timeout=30)
    diff = str(msg.content)
    if diff == 'a':
        max = 10
        number = random.randint(1,10)
        await ctx.send('You have 5 guesses')
        await ctx.send('Pick a number between 1 and 10')
    elif diff == 'b':
        max = 50
        number = random.randint(1,50)
        await ctx.send('You have 5 guesses')
        await ctx.send('Pick a number between 1 and 50')
    elif diff == 'c':
        max = 100
        number = random.randint(1,100)
        await ctx.send('You have 5 guesses')
        await ctx.send('Pick a number between 1 and 100')
    else:
        ctx.send('Please try the command again...')
        return
    msg = None

This is the check I am using:

    def check(author):
        def inner_check(message):
            # author check
            if message.author != author:
                return False

            # inner check
            try: 
                int(message.content) 
                return True 
            except ValueError: 
                return False

When I respond to the bot in-chat with "a", "b" or "c", I get no response. I disabled the command for everyone but me whilst I tried to fix it, but I have no idea how to start.

I would appreciate an answer, as I don't see the solution myself, thanks! [I didn't show the actual number game, because it is irrelevant and long]

Upvotes: 0

Views: 396

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 61062

Just create a new check function that does what you want.

def abc_check(author):
    def inner_check(message):
        return author == message.author and message.content in ('a', 'b', 'c')
    return inner_check

Upvotes: 1

Related Questions