lmariscal / twitchirc

Twitch Bot Development made Easier | DEPRECATED
Other
39 stars 15 forks source link

if (message.contains("test") && user == "chrisderwahre") error #34

Closed chrisderwahre closed 6 years ago

chrisderwahre commented 6 years ago

Hey! Im getting an error if i want to check the user, am i doing something wrong? error: Operator '==' can not be applied to 'com.cavariux.TwitchIRC.Chat.User' java.lang.String

Full code:

if (message.contains("test") && user == "chrisderwahre") { this.sendMessage("Hey Bot Admin!", channel); }

mvarendorff commented 6 years ago

Use && user.toString().equals("chrisderwahre"). Unless you have primitives (int, float, long, boolean, etc), you compare Objects with .equals. In this case you want to compare a user to a string, you first have to make them the same class with user.toString() and then compare them with equals. You might get a warning that toString() is deprecated. Ignore that, please :) It does not do anything bad and will be fixed sometime soon.

chrisderwahre commented 6 years ago

Thank you.