Search code examples
pythongoogle-sheetsdiscorddiscord.pygspread

How do I find the user's name in a form?


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


Solution

  • 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