0

I'm trying to make a guessing game in a Discord bot. I have the game done, but not sure how to retrieve user input via Discord. I know about that wait_for method to get a specific response. The problem is that it checks only for specific strings. I am looking for way to check for a list of possible strings and store whichever one it checks true for. (EX: If one of the strings is used as the it stores that input to a variable)

possible_numbers = [i for i in range(1,51)]
def check(m):
    if m.content in possible_numbers:
        return m.content == m.content and m.channel == channel
guess = await client.wait_for('message', check=check, timeout=120.0)

I am expecting for something along these lines to successfully check if m.content is in possible_numbers, and if so just retrieve m.content and store it as "guess". Currently it just outs puts nothing and if I change it to:

def check(m):
    return m.content == '1' and m.channel == channel
guess = await client.wait_for('message', check=check, timeout=120.0)

It will only accept whatever is the direct string it checks for.

Victor
  • 3
  • 5
  • May I ask why you return `m.content == m.content`? Should always be true – 101arrowz May 10 '19 at 17:59
  • Here's the code I use, it checks for multiple channels/authors/messages: https://stackoverflow.com/questions/55811719/adding-a-check-issue/55812442#55812442 – Patrick Haugh May 10 '19 at 18:03

2 Answers2

1

possible_numbers = [str(i) for i in range(1,51)]

You can't compare an int to a string with ==. So, make the list contain only strings.

101arrowz
  • 1,825
  • 7
  • 15
0

You could perhaps have a method that will interpret the entire message they post to trigger the command?

@bot.event
async def on_message(ctx): # compute every message, not just commands
    message_being_interpreted = ctx.content.lower()
    print(message_being_interpreted ) # will print all messages
    # do things to parse it like this
    if "!guess" in message_being_interpreted:
        pass # or do stuff

This would work great if the user is supposed to supply the argument with their command like !guess 17463, but you could also make it so users just have to type a guess like 17463, and then when they input the correct guess it triggers some event.

Reedinationer
  • 5,661
  • 1
  • 12
  • 33