Banker 175 Posted September 29, 2016 Hey, so im fairly new to making my own bot scripts. I am wanting to create my own dice/games bot where if i for example send "!dice" or "!roll" in a clan chat, the bot will send "<Username> Rolled <Random Num (1-100)>" to the clan chat. If someone could show me either snippets of essential pieces of code, or tell me what i will actually need to use to send the messages and detect the command etc it would be appreciated. from what i have seen i believe I would have to use getKeyboard().type() to send a message to the chatbox but i am lost as to where to detect the command etc. Thanks.
Diddy 265 Posted September 29, 2016 Implement MessageListener pass Message message in the method and there you go
Banker 175 Author Posted September 29, 2016 Implement MessageListener pass Message message in the method and there you go Thanks but, How would i use the messagelistener to listen for a specific command though?
Banker 175 Author Posted September 29, 2016 you know, something like if(message.contains("!roll"){ Ahh thanks, ill try it out, if i have any problems ill make sure to post here or dm you @Override public void onPlayerMessage(Message message) { playerMessage = message.getMessage(); uname = message.getUsername(); } in the onLoop() {} would i just do @Override public int onLoop() { if(playerMessage == "!roll") { getKeyboard().type("/~ "+uname+" ~ Rolled: "+rand.nextInt(101)); } return 0; } This doesnt seem to work when i run it and send !roll in the clan chat, am I doing something wrong?
Banker 175 Author Posted September 29, 2016 use .equals() for Strings So like this: if(playerMessage.equalsIgnoreCase("!roll")) Update: it didnt work when i typed "!roll" into the cc with another account. onLoop() code below: @Override public int onLoop() { if(playerMessage.equalsIgnoreCase("!roll")) { getKeyboard().type("/~ "+uname+" ~ Rolled: "+rand.nextInt(101)); } return 0; }
Dreamlicker 750 Posted September 29, 2016 So like this: if(playerMessage.equalsIgnoreCase("!roll")) Update: it didnt work when i typed "!roll" into the cc with another account. onLoop() code below: @Override public int onLoop() { if(playerMessage.equalsIgnoreCase("!roll")) { getKeyboard().type("/~ "+uname+" ~ Rolled: "+rand.nextInt(101)); } return 0; } How are you assigning playerMessage? I'd recommend handling messages within one of the onMessage methods.
Banker 175 Author Posted September 29, 2016 How are you assigning playerMessage? I'd recommend handling messages within one of the onMessage methods. Im using the following code and just assigning the message and username to a variable. @Override public void onPlayerMessage(Message message) { playerMessage = message.getMessage(); uname = message.getUsername(); }
Dreamlicker 750 Posted September 29, 2016 Im using the following code and just assigning the message and username to a variable. @Override public void onPlayerMessage(Message message) { playerMessage = message.getMessage(); uname = message.getUsername(); } Try using the AdvancedMessageListener, this contains a specific method for handling clan messages.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.