0

So I am currently working on a Discord.py bot and am trying to find if the user is already registered through the bot with GSpread. I've tried a few things like :

if findUser is None:
   print("User not found!")
if findUser:
   print("Found user!")

It worked when the user was found, but when I removed the username from the spreadsheet, it broke.

@bot.command()
async def finduser(message):
    user = (message.author.name+message.author.discriminator)
    print(user)
    findUser = sheet.find(user, in_column=3)

    if findUser:
        print("User found!")
    else:
        print("User not found!")

Anyways, if anyone could help me out, that would be awesome!

-ekalb2020

ekalb2020
  • 3
  • 1

2 Answers2

1

What about just changing the conditions? Since it worked on the first example, you could just use it in the second example

@bot.command()
async def finduser(message):
    user = (message.author.name+message.author.discriminator)
    print(user)
    findUser = sheet.find(user, in_column=3)

    if findUser is None:
        print("User not found!")

    else:
        print("User found!")
Oliver Hnat
  • 797
  • 4
  • 19
  • I don't know haha. I'm incredibly confused now. All I really know is that I want to check if the user is found in the sheet and print a statement saying if they were or weren't. Your/my (idek anymore) fix doesn't work btw. – ekalb2020 Nov 09 '20 at 08:46
0

I figured it out! Was fairly simple, just was misunderstanding how to use the statement!

@bot.command()
async def finduser(message): 
    user = (message.author.name+message.author.discriminator)
    print(user)
    
    try:
        sheet.find(user, in_column=3)
    except:
        print("User not found!")
    else:
        print("User found!")

Find more on the try statement here: Determine if variable is defined in Python

ekalb2020
  • 3
  • 1