Skip to content
Sign upLog in
← Back to Community
Dont know but need help!!!!
Profile icon
Awesomemode

So I did everything that was told in the tutorial but I got one huge error.

image

I dont even know what it is.

it matches the tutorial here.

image

I would like if anyone can help me that would be great (Feel free to look through the ELMO BOT Repl code!)

Answered by RYANTADIPARTHI [earned 5 cycles]
View Answer
Voters
Profile icon
Awesomemode
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

Solution

in the tutorial, line 32 which contains msg = message.content, is tabbed a little bit more than in the tutorial.

  • you

Screenshot 2021-01-02 at 6.34.12 PM

  • tutorial

Screenshot 2021-01-02 at 6.34.45 PM

see the difference? Your code should look like this.

import discord import os import requests import json import random client = discord.Client() sad_words = ["sad", "deppresed", "unhappy", "miserable", "angry", "deppressing"] starter_encouragements = [ "Cheer up!", "Hang in there.", "You are a great person!" ] def get_quote(): response = requests.get("https://zenquotes.io/api/random") json_data = json.loads(response.text) quote = json_data[0]['q'] + " -" + json_data[0]['a'] return(quote) @client.event async def on_ready(): print('We have logged in as {0.user}'.format(client)) @client.event async def on_message(message): if message.author == client.user: return msg = message.content if msg.startswith('$inspire'): quote = get_quote() await message.channel.send(quote) if any(word in msg for word in sad_words): await message.channel.send(random.choice(starter_encouragements)) client.run(os.getenv('TOKEN'))

that way, it won't be assigned before local var, as the error states. And you are following the tutorial correctly.
That should work

Profile icon
Awesomemode

HOLY SMOKES MATE YOU ARE SO AMAZING I WOULD LOVE TO PUT YOUR NAME ON MY DISCORD BOT FOR HELPING ME THIS WOULD HAVE NEVER BEEN DONE WITHOUT [email protected]

Profile icon
RYANTADIPARTHI

@Awesomemode
Thanks a lot! and no problem :)

Profile icon
Awesomemode

Happy that your here!

@RYANTADIPARTHI

Profile icon
RYANTADIPARTHI
Profile icon
SixBeeps

Line 32 is tabbed 1 more than it should. Untab once to match the code in the tutorial