Skip to content
Advertisement

String contents not being replaced within the same method as string declaration. (JDA)

I am trying to store a randomly generated string in a string variable to use for in for other things. Basically, it is a password generator that stores the password for use with commands that need it. The application seems to have problems with storing the password for later use though. Code and output vs expected below.

JavaScript

For some reason, in the //password generator section, stored is replaced with a random string just fine but when you enter that password using the !setpassword command, stored is empty so it is like the replace method I used in the password generator section is not being saved even though the StringBuilder has the proper scope for the method. I’ve been trying to do this for a bit now. I have tried with String, StringBuilder, and StringBuffer to see if any had different results but all had the same output.

Output:

JavaScript

Expected Output:

JavaScript

In the back of my mind I am thinking it may be how I am generating the random password and storing it but I am not sure since this seems to be a problem with the string declaration itself and its scope

Advertisement

Answer

Try:

JavaScript

to

JavaScript

OR

try to add this above the public void onGuildMessageReceived(GuildMessageReceivedEvent event):

JavaScript

Everytime you want to use it, do this.Stored

See if it works then.

Also, try to add a statement to send in dms the current stored string at random points in the code this is what i call print–debugging to simply see when the value changes to reduce our search.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement