Ask coding questions

← Back to all posts
I cant find the error
TheSpeakingLava (0)

I cant find the error in my code... It just says invalid syntax, but i cant find whats wrong.... https://im-boi2.thespeakinglava.repl.run

Answered by ArchieMaclean (645) [earned 5 cycles]
View Answer
Commentshotnewtop
ArchieMaclean (645)

f strings only support variables - you are trying to use a function (random.choice(responses)) inside (on line 45). This doesn't work. An example fix is:

async def _8BALL(ctx, *, question):
  responses = [
    # ...
  ]
  response = random.choice(responses)
  await ctx.send(f'Question: {question}\nAnswer: {response}')

Also, make sure that the await is on the same indentation level as the rest of the function (like above).

Please mark this as the answer if it solved your problem :)

ArchieMaclean (645)

@TheSpeakingLava On line 45, you had

  await ctx.send(f'Question: {question}\nAnswer: {random.choice(responses)}')

but having random.choice in there doesn't work. So instead you can do

response = random.choice(responses)
await ctx.send(f'Question: {question}\nAnswer: {response}')
TheSpeakingLava (0)

@ArchieMaclean Do u have any idea of how I can make it run 24/7 without interacting with it?