Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Private Dice Bot


    Banker
     Share

    Recommended Posts

    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.

    Edited by Banker
    Link to comment
    Share on other sites

    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?

    Link to comment
    Share on other sites

    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?

    Link to comment
    Share on other sites

    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;
    }
    Link to comment
    Share on other sites

     

    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.

    Link to comment
    Share on other sites

    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();
    }
    
    Link to comment
    Share on other sites

     

    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.

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.