-1

I am making a discord bot using python.

I have a function

def search(userName):
    # ...

but the userName MAY contain spaces

Eg.

Enter userName: Me Head

and I want the function to read bot arguments given and join them together so it forms "MeHead"

Currently if I try to run my search(userName) function with two inputs it will just take the first input so

Enter userName: Me Head 

will just run search("Me") and ignore anything after that first input

bruno desthuilliers
  • 75,974
  • 6
  • 88
  • 118
MeHead
  • 7
  • 1
  • 1
  • 5
  • Shouldn't there still only be a single argument, even if the username contains spaces? Either it's a single string (without spaces) `'John'`, or it's a single string (with spaces) `'Me Head'`. – mkrieger1 Jun 25 '18 at 10:10
  • Anyway, check out https://stackoverflow.com/questions/919680/can-a-variable-number-of-arguments-be-passed-to-a-function – mkrieger1 Jun 25 '18 at 10:11
  • Looks like it should be responsability of the caller function (the one calling your `search()` function) to make sure it passes the user input as a single string... – bruno desthuilliers Jun 25 '18 at 10:21
  • The input is kinda different because it's given from a discord server so the string will end when the user types a space – MeHead Jun 25 '18 at 10:21
  • Could you include the entirety of at least the first few lines of the function, including any decorators that you've applied to it? `discord.py` does a lot of parsing behind the scenes with certain decorators, especially the `Bot.command` decorator. – Patrick Haugh Jun 25 '18 at 13:08

1 Answers1

0

The input is received is a string, so it does not matter if there are or no spaces. To remove spaces, you must use the function:

str.replace(" ", "")
Baruch Gans
  • 1,415
  • 1
  • 10
  • 21
  • This works if I do it on python IDLE but when I try to replicate it on discord it won't work. The string ends after the first space – MeHead Jun 25 '18 at 10:42