#Dotenv Help
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
.env is for node?
Inside of my .env file, I have DISCORD_TOKEN=<token>
that's for node though
Oh
Oh wait a min... the tutorial I was watching is for Node... 
So there's no such thing in Java, then?
for what ?
Title's misleading... It says "Java" ๐
.env
you can use anything else for java like json, a config file or whatever
what's that ?
Environment file to store things like bot tokens
yea
nodejs has a .env package that you can store env vars in. on startup, it'll load the env vars
if you are using srping for example, you can use application.properties
but here
just create a file whereever you want
the closest we have is Properties
and read it
Is .txt valid?
you can create a .properties file and store all your stuff in there discord_token=1234
and it'll have stuff like this
not sure thats what you want
public static void main(String[] args) {
Properties properties = new Properties();
String propertiesFilePath = "path/to/your/config.properties";
try {
properties.load(new FileInputStream(propertiesFilePath));
String value = properties.getProperty("discord_token");
} catch (IOException e) {
e.printStackTrace();
}
}
Is Properties like part of the standard Java library?
yes
Awesome
no, Class#getResourceAsStream
@sly holly
Oh?
i don't wanna explain that to him
Ok well Ig what I meant to ask was...
Do I have to install it as a dependecy in my pom.xml file?
no
but basically, you should have a resources folder that you're supposed to bang that stuff in
but ala can explain if he wants
unless you want to use another format like json
when you generate a maven project
it will always have a resource folder
so you can simply use
Properties properties = new Properties();
properties.load(MyClass.class.getResourceAsStream("/config.properties");
yes
also, don't forget to gitignore it, so you don't commit your token by mistake
you can also use something like detect-secrets to ensure that you don't commit it
Ty for reminding me
and instead, you can add a config.properties.template that you will commit so anyone cloning your project can just copy paste this file and complete it
I stole this idea from tj bot
Lol
Oh, I deleted my token on accident
Let me regen one sec
๐
IOException e in Java is basically like saying store the error as e, right?
Ah ye
Ok good
Awesome, this language is very intuitive
YES! Thank you! Finally
That should not have taken me that long...
Man... Why do ppl market their videos with "Java" if it's JavaScript? 
Tysm guys
clickbait
wdym
Like e is the error object, right?
yes
If I print e, I'll get the error?
yes, but there is better, use e.printStackTrace()
printing e directly only give minimal info
which language did you use before ?
I made all my bots in Python, but I'm transitioning to C++/Java in uni so I wanna venture out
Arrow functions are interesting too, need to learn this
Not even sure what's going on here really
python folks are usually the ones to trash talk java because of it's verbosity(but mostly just stop at public static void main) ๐
Nah, but I always found it interesting how articulate you could be with Java
I don't even get that in C++
yea i like that about java, no comments on c++ since havent used it. Those first few lines at the top of a c++ program scares me.
C++, tbh, I don't really like the syntax in that language ๐คฃ
I just started with C++
This ^
I never bothered learning lambda functions, ngl
So I'm still lost
Ah, Javacord API conveniently has lambdas under "Essential Knowledge"
It's essential knowledge in vanilla java
I see... I'm currently struggling to register a SlashCommand... ๐
Maybe consider JDA instead of javacord
I think most people are familiar with that
Javacord might be better but you're likely to get more help from us lot specifically because our server bot uses that, so you can reference it
@sly holly โ
I was just thinking about giving up on Javacord... Seems like YT has a lot more tutorials on it, too... And this guy I really like to watch code named Anson uses it too, so... Maybe I'll switch over ๐ Ty
@naive oyster
Talking about everyone using JDA, not Javacord
@sly holly
Your question has been closed due to inactivity.
If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.
Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.
When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.
Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.
With enough info, someone knows the answer for sure ๐