#๐ Error
151 messages ยท Page 1 of 1 (latest)
@azure valley
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
What's the full traceback?
How?
Insatll pip discord?
Install*
pip install discord
Ok done now lemme try.
py -m pip install discord
???????????
anyways that seems to not be a problem.
btw i am so sorry
that i cannot help ou
because i have no experience of discord bots in python
i am so sorry
please help thi scase
It looks like you don't have an API key in you environment
Im not using one. Its just If message contect = !hello then It replies with Hello!
You'll need to get an API key
For what?
Im new to Python
Im using a 3 year old vid.
U have a vid that I can use that will work?
@azure valley create a .env file with
TOKEN = yourbottoken
Thats what I've done.
Yeah.
did you install dotenv-python ?
They're not using it
This will hopefully fix your error
How do I add It?
With the other way.
yet
https://ask.replit.com/t/how-to-add-environment-variables-into-replit-in-python/19356/2
first google result
they wont need it
Likt this?
Like*
Try it
in the client.run() u can replace what's inside with my_secret
Since you're already defining it before
no, client.run(my_secret)
did you set MY_SECRET = yourtoken
in the Secrets tab?
Yeah the value as my token
try import load_dotenv ig py from dotenv import load_dotenv load_dotenv()
I'm not sure then... someone more experienced with replit can help perhaps
What do I pput In the string?
()
nothing
try to run it
It didnt work
what is the error
Ima reset my token after
But Is this correct In my ENV file?
oh ok
wait a min
your token not in TOKEN = '..........'
ig you forgot the ' at last
try my_secret = os.getenv("TOKEN")
well you are trying to access MY_SECRET variable but you named it TOKEN
you have 2 ) at the end?
also why you create MY_SECRET variable when you dont use it
when you directly pass token to .run
Idk but I removed the ) but It still says Its there.
just remove that variable
Its my first time ever coding and I made It.
i wouldnt start from discord bot it will be confusing a lot
i recommend first learning at least basics of python
I have I meant this Is my first time coding a bot.
I used to make python stuff before.
Like micro bits.
And just In the console.
doesnt look like if you dont see a problem with 2 closing )
I thought you meant line 25 not 4.
it work ?
if you still want to try your best at discord bots
i recommend hiting this guide https://fallendeity.github.io/discord.py-masterclass/creating-a-bot/
A hands-on guide to Discord.py
this examples will work 4sure and wont be so outdated
I did user a 3 year old vid lol.
User*
Use*
this guide was written pretty recently
and for past 3 years few things changed in the lib
.env (dotenv) files are a type of file commonly used for storing application secrets and variables, for example API tokens and URLs, although they may also be used for storing other configurable values. While they are commonly used for storing secrets, at a high level their purpose is to load environment variables into a program.
Dotenv files are especially suited for storing secrets as they are a key-value store in a file, which can be easily loaded in most programming languages and ignored by version control systems like Git with a single entry in a .gitignore file.
In Python you can use dotenv files with the python-dotenv module from PyPI, which can be installed with pip install python-dotenv. To use dotenv files you'll first need a file called .env, with content such as the following:
TOKEN=a00418c85bff087b49f23923efe40aa5
Next, in your main Python file, you need to load the environment variables from the dotenv file you just created:
from dotenv import load_dotenv
load_dotenv()
The variables from the file have now been loaded into your program's environment, and you can access them using os.getenv() anywhere in your program, like this:
from os import getenv
my_token = getenv("TOKEN")
For further reading about tokens and secrets, please read this explanation.
and this should explain you how environment variables work and how to use them in code
I got the bot running but now It says await outside of function.
just check the guide i linked
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.