r/pythonhelp • • Feb 15 '21

Cannot figure out invalid syntax error.

Im currently making a discord bot that pulls data from yahoo_fin api and posts the data in the channel. I cannot figure out why the code is giving me an error on line 23, start = 0. Can someone help me?

2 Upvotes

8 comments sorted by

View all comments

Show parent comments

1

u/nick4wow Feb 15 '21

Looks like i have an issue with with await message.channel.send() i dont think the while true statement is attached to that command. How would i do that?

1

u/WhenRedditFlies Feb 15 '21 edited Feb 15 '21

What does message.channel.send() do? I'm only vaguely familiar with the discord API.

Also a slight error I made in my first comment, you need to have all the stuff inside the curly braces (with the exception of "while true:") be 2 spaces to the right of "while true:", because python stops running what's in the while loop when the code comes back to the same indentation level (number of spaces).

Nvm I have just realised it sends a message to the channel. I now see there are a large number of things that appear to be mistakes in your code within that section you put curly braces around, would you mind explaining to me what you want it to do, so I can help you indent things a bit better?

1

u/nick4wow Feb 15 '21

When the command "!stockinfo" is inputed by an end user on my disord, i want the while loop to work by the bot in my channel. I want the botbto say "enter short notation", wait for the user input, and when reply with "comany_name is x amount of dollars per share." And then i want the bot to ask if the user wants to look at another stock yes or no. If yes then loop back of no then stop loop

1

u/WhenRedditFlies Feb 15 '21

Ah, that may mean your project is a little more complex than it first seems, because to "wait for a user input" on an event based system (like discord API) is a lot different to running "freeze the program until the user presses enter" in a text based only python interpreter interaction, where the program doesn't also simultaneously need to look out for other interactions. It can be done, you can setup a global variable saying which point the last interaction was (maybe 0 for not having done anything yet, 1 for asking yes or no etc), so that when you receive an input from the user, you can remember what question was asked, and how to respond to that answer.

A while loop is therefore not the answer here, and you might want to look at moving the stuff in the while loop to a slightly different program flow.

Using input() will actually stop the bot completely until the window running the bot has been given an input. So I think the little red line in your screen shot is a little misleading, there are different problems that will throw you off much more compared to the syntax there.

Please keep me posted, I'm a little invested in seeing your project work now :)

1

u/nick4wow Feb 15 '21

Ill post once i get some progress. There is syntax for client.event that waits for user input that i found on stackoverflow that i can try later tonight.

Honestly you can join my discord and i can work on it tonight live if you have some free time. Ill probably be working on it for a few hours lol