I keep getting errors with an "if var.startswith" statement [closed]
I'm trying to make it so that I can input someone into console and have it set a variable to it, and every time with the if statement it gives the error
File "main.py", line 58, in <module>
if meInput.startswith("%send"):
AttributeError: 'builtin_function_or_method' object has no attribute 'startswith'
Here's the code:
if input.startswith("%send"):
myinput = input.split(" ", 2)[2]
channel = client.get_channel(12324234183172)
I've tried putting it into a variable such as variable = input
then changing the if statement to match the variable, but it does the same thing.
Solution 1:
Read the error message carefully! It is telling you that input
is not a string, but a function — a function that would return a string if you called it, but you didn’t. Try this instead:
if input().startswith("%send"):
Note the parentheses. That is how you call a function in Python, and in most other languages.