@sly.automation first boting project #botting #programming ♬ original sound – sly automation
Step 1: Setting Up Your Project
Before you start coding your OSRS bot, it’s important to build a well-organized development environment. Step 1 focuses on creating the structure of your Python project in PyCharm a professional-grade IDE (Integrated Development Environment) that makes it easier to write, debug, and manage your scripts.
This setup stage may seem simple, but it’s critical for long-term stability and readability. A well-structured project will help you avoid confusion later when you expand your bot to handle multiple tasks like woodcutting, mining, or fishing. It also ensures that every file and module has a clear, specific purpose.
for my github source: https://github.com/slyautomation/osrs_basic_botting_functions/
1.1 Creating a New Project
Start by opening PyCharm. If this is your first time using it, you’ll be greeted by the welcome screen where you can select “New Project.”
Choose a location on your computer where you want your project to live somewhere easy to access, such as your Documents or a dedicated “OSRS_Bot” folder.
Give the project a clear name, for example:
osrs_botting_functions
When PyCharm asks for the Python interpreter, make sure to enable “New Virtual Environment” (venv). This creates an isolated workspace that only contains the dependencies (modules) for this specific project. It prevents version conflicts with other Python projects you might have on your computer.
Once you click “Create,” PyCharm will generate a base project folder with its own environment, ready for coding.
1.2 Organizing the Project Files
With your project open, the next step is to create three separate Python files that will divide your code into logical components. This approach follows good programming practices, where each file has a single, well-defined responsibility.
core.pyThis file handles the technical setup of the RuneLite client window. It will contain functions that locate, resize, and position the game window so that all automation happens in the same place every time you run your bot. Think of this as the “foundation” layer of your project.functions.pyThis is where you’ll store reusable functions, such as color detection, image recognition, or screen capture. Keeping these in a separate file helps you stay organized as your bot grows more complex. Any function that might be useful in multiple scripts should live here.commands.pyThis is the control center, or the “main script.” It will bring everything together by importing functions from bothcore.pyandfunctions.py, then running the actual automation logic (for example, detecting trees, clicking them, and dropping logs).
In PyCharm, you can create each file by right-clicking on the project folder in the sidebar, selecting New → Python File, and giving it the appropriate name.
1.3 Why File Structure Matters
Separating your logic into these files isn’t just about neatness it’s about maintainability and scalability. As you add more features to your bot (say, fishing, mining, or combat), you’ll be able to reuse your existing setup and detection functions without rewriting everything.
For example, your core.py will stay the same across all future projects since every automation task depends on finding and locking the game window. Meanwhile, you can add new behavior-specific scripts like fishing.py or mining.py that rely on the same shared functions file.
This modular design also makes debugging far easier. If something goes wrong with color detection, you’ll know to look inside functions.py. If the game window isn’t being found, the issue is probably in core.py. And if your woodcutting logic loops endlessly, it’s most likely in commands.py.
1.4 Preparing for Version Control (Optional but Recommended)
If you plan to develop multiple versions of your bot or collaborate with others, it’s a good idea to use Git for version control. PyCharm integrates directly with GitHub, so you can track your changes and easily revert to previous versions if something breaks.
To set this up, go to:
- VCS → Enable Version Control Integration → Git
Then, commit your initial files. This gives you a snapshot of your clean starting point before any major changes are made.
1.5 Confirming Your Environment Works
Before you move on, double-check that your Python interpreter is working correctly. You can do this by opening any of the three Python files and writing a simple test line like:
print("Setup complete.")
Run the file (Shift + F10 by default in PyCharm). If it prints the message in the console without errors, your environment is ready to go.
In summary, Step 1 is all about laying the groundwork. By creating a clean project, dividing your code into purpose-driven files, and ensuring your environment is correctly configured, you set yourself up for success. This structure will save you countless headaches later when your scripts get longer, your automation logic grows more advanced, and you start managing multiple botting functions across different OSRS skills.
Step 2: Installing Python Modules
Before writing any code, your Python environment needs a few key modules that handle automation, screen interaction, and color or image processing. Installing these dependencies early ensures that everything you write later will run smoothly, and that PyCharm can provide proper code completion and error checking while you work.
Once you’ve created your project in PyCharm, the next step is to open the project’s Python interpreter settings. You can do this by going to File → Settings → Project → Python Interpreter. Here, you’ll see a list of installed packages for your project’s virtual environment. A virtual environment is essentially a self-contained workspace that keeps the libraries for one project separate from everything else on your computer, preventing conflicts between different Python projects.
Click the small “+” icon in the top right of that list to open the package installer window. This is where you’ll search for and install the libraries your bot will rely on. There are three core modules you need for this tutorial:
- PyAutoGUI
This library allows your Python scripts to control the mouse and keyboard just like a real person would. It can move the cursor, click on specific coordinates, type text, and press or release keys.
In the context of OSRS automation, PyAutoGUI is what makes the bot “act.” For example, when your color detection function finds a tree or a log icon, PyAutoGUI moves the mouse to that location and clicks. Later, it’s also used to drop logs or interact with menus using simulated keystrokes. - PyWin32
This package gives Python the ability to communicate directly with Windows’ internal functions especially useful for managing windows and system-level interactions.
You’ll use PyWin32’swin32guiandwin32conmodules insidecore.pyto find and position the RuneLite window. Without it, your bot wouldn’t know which window to target, nor could it ensure the game stays in the correct position each time the script runs. PyWin32 acts as the link between your Python code and the Windows graphical user interface. - OpenCV-Python
OpenCV (Open Computer Vision) is a powerful library for image processing and computer vision. In this project, you’ll use it for color detection, object recognition, and template matching.
This means your bot won’t rely on pixel-perfect coordinates it will actually look at what’s on the screen. For example, OpenCV can find regions that match a specific color (like the yellow outline around a tree marked in RuneLite) or detect images such as the wood icons in your inventory. It essentially gives your bot “eyes” so it can make decisions based on what it sees.
To install each one, simply type their names in the PyCharm package search bar (e.g., “pyautogui”), click Install Package, and wait for the confirmation. Alternatively, you can use the terminal inside PyCharm and run:
pip install pyautogui pywin32 opencv-python
When the installation finishes, it’s a good habit to confirm that all modules were installed correctly. You can do this by opening a new Python file in your project and trying simple import statements like:
import pyautogui
import win32gui
import cv2
If no errors appear, everything is ready.
At this stage, you’ve effectively equipped your environment with the essential tools for OSRS automation. Each module plays a distinct role:
- PyAutoGUI handles interaction,
- PyWin32 handles window control, and
- OpenCV handles perception.
Together, they form the backbone of almost every automation script you’ll create. With these installed, you can confidently move forward to the next step setting up core.py to integrate these modules into a controlled and predictable automation environment.
Step 3: Setting Up core.py
The core.py file is the foundation of your entire automation framework. Its purpose is to establish control over the RuneLite game client specifically, to find the game window, move it to a consistent position, and lock it into a predictable size. This setup ensures that every other part of your bot (such as image detection, color scanning, and mouse clicking) will always occur in the right locations on screen, regardless of when or how you launch RuneLite.
When working with automation based on screen coordinates or image recognition, consistency is absolutely critical. If the RuneLite window is shifted even a few pixels or has a different size, all of your coordinates and image detection areas become inaccurate. For this reason, core.py handles the environment setup before any task-specific functions run.
You begin by importing the necessary libraries, usually win32gui and win32con from the PyWin32 package. These allow Python to communicate with Windows’ graphical interface, so you can find application windows by name and move or resize them. You’ll also typically import pyautogui to control the mouse and keyboard, and time for short pauses between actions.
The first main function in core.py is responsible for locating the RuneLite window by its title. When RuneLite is open, Windows tracks it as a top-level window with a name like “RuneLite – your_username”. Your script can use win32gui.FindWindow() to search for that name and get a handle to the window. If the handle is not found, you can raise an error that tells the user the window name is incorrect or that RuneLite isn’t currently open. This step ensures that the bot won’t try to run without the correct game client active.
Once the window handle is found, you use win32gui.MoveWindow() to set its position and size. A common setup is to move it to coordinates (0, 0) the top-left corner of the main monitor and fix its dimensions to something like 800×600 or whatever size your bot’s vision and coordinate system were designed for. This guarantees that every color detection and image recognition call later in your script will operate over the same area of pixels.
You can also include a short delay after repositioning the window to give runescape time to redraw its contents before the automation starts. For instance, a small time.sleep(1) ensures the interface is stable before color detection begins.
A nice enhancement is to create a wrapper function that both finds and repositions the window in one call, perhaps named focus_client(). This function could check if the window exists, bring it to the foreground using win32gui.SetForegroundWindow(), and then resize it automatically. That way, your main script can simply call focus_client() before running any automation functions, and the environment will always be correctly prepared.
In short, core.py doesn’t handle gameplay logic directly it’s all about the environment setup and reliability. Its job is to make sure that every time you press “Run” in PyCharm, your bot knows exactly where the runescape window is, how big it is, and which region of the screen to analyze. Once that foundation is in place, you can safely build higher-level functions like woodcutting, mining, or fishing without worrying about alignment issues or inconsistent results.
Step 4: Creating the Main Function Script (Expanded Explanation)
Once your project structure and core setup are complete, it’s time to build the heart of your automation: the main script.
This step focuses on writing the control logic that ties everything together finding the game window, detecting trees, clicking to chop them, and automatically dropping logs when the inventory fills up.
The file that handles all this logic is called commands.py, and it serves as the “brain” of your bot.
It’s where the automation flow is coordinated: you’ll import the helper functions you created, call them in the right order, and manage the overall timing and conditions for when things should happen.
4.1 Purpose of commands.py
In programming terms, commands.py is your execution layer.
It doesn’t worry about how things are done (that’s handled in functions.py and core.py) instead, it focuses on when and in what order tasks occur.
You can think of it as the “director” of the automation:
core.pysets the stage (window size and position),functions.pyprovides the tools (color detection, mouse clicks, OCR),- and
commands.pytells those tools when to act.
This separation of responsibility keeps your code modular, readable, and much easier to debug or expand later.
If needed i usually name my commands.py after a specific task like woodcutting.py or mining.py
4.2 Setting Up Imports
The first few lines of commands.py will bring in everything you need from the other scripts and libraries.
Typically, it looks something like this:
from core import *
from functions import *
import time
Here’s what’s happening:
- You import everything from
core.pyto make sure your RuneLite window is found and positioned before anything else runs. - You import your helper functions (for example, image detection or color scanning).
- You import
timeto add small, randomized delays between actions, helping your automation appear more natural and reducing CPU load. - You tailor the functions so its purpose matches what you need the commands to achieve.
4.3 Establishing the Flow
Before jumping into loops or clicks, it’s a good practice to write a clear plan of your automation logic almost like a flowchart.
For a simple woodcutting bot, the logic goes something like this:
- Focus or reposition the RuneLite window.
- Continuously search the screen for the color or image associated with trees (the ones you’ve marked in RuneLite).
- Move the mouse to that location and click.
- Wait a few seconds for the chopping animation to finish.
- Check whether your inventory is full.
- If full, drop all logs by simulating a shift-click sequence on each wood icon.
- Repeat from step 2 indefinitely or until a condition is met.
Your script will execute these steps in a continuous loop until you stop it manually or implement a timed duration.
4.4 Detecting and Clicking Trees
The detection logic depends on the functions you’ve already written in functions.py.
For example, you might use a function called find_object() that scans the screen for a color range (like the amber highlight from RuneLite’s Object Marker plugin).
When that function finds a region matching your target color, it returns the coordinates (X and Y) of that area.
Your main script then passes those coordinates to a click function perhaps something like click_target(x, y) which uses PyAutoGUI to move the mouse and click on that exact spot.
You can also add a short random delay after each click to mimic human behavior. For example:
time.sleep(random.uniform(1.5, 3.0))<br>This variation prevents your script from acting in a perfectly predictable rhythm, which helps with realism.
4.5 Monitoring the Inventory
The next major component is detecting when your inventory is full.
This is typically done using image recognition. Earlier, you captured an image of your wood icon (wood_icon.png) and saved it to your project folder.
Now, your script can use OpenCV to repeatedly check whether this image appears in the inventory area.
If the number of matches equals or exceeds a certain threshold say 27 or 28 that means your inventory is full.
At that point, your script will call another function, like drop_items(), which performs the automated shift-click process to clear space.
Inside drop_items(), PyAutoGUI presses and holds the Shift key, then clicks each detected wood icon in turn.
Once finished, it releases the Shift key and resumes chopping.
4.6 Continuous Loop and Timing
Most automation scripts use a while loop to run continuously until a condition is met.
In your woodcutting script, that condition could be something like:
while True:
# run detection and click logic
or a controlled variant such as:
while j < 10:
# run woodcutting logic for 10 iterations
You can include a random break interval within the loop for example, every 10 to 15 seconds the script pauses briefly to simulate idle time.
This not only mimics human behavior but also reduces resource usage.
During each iteration, your console will print logs such as:
- “Detected X yellow regions”
- “Clicked at coordinates (512, 384)”
- “Inventory count: 26”
- “Dropping items…”
These logs are useful for tracking progress and debugging, since they give you real-time insight into what your bot sees and does.
4.7 Error Handling and Graceful Stops
It’s good practice to wrap your main loop in a try/except block.
This way, if something unexpected happens (like the window title changing or a module failing), the script can exit gracefully rather than crashing abruptly.
You can even include a manual stop condition, such as pressing a specific key (for instance, the Caps Lock key) to break out of the loop.
This allows you to end the automation safely without closing PyCharm or killing the Python process.
4.8 Testing the Script
Before letting the bot run for hours, test it in small bursts.
Run the script while watching your RuneLite window you should see your cursor move toward a marked tree, click, wait, and repeat.
When your inventory fills up, the script should automatically recognize the logs and begin dropping them.
If anything doesn’t align correctly (for instance, clicks are off by a few pixels or detection seems inconsistent), double-check your window positioning in core.py and your color thresholds in functions.py.
Fine-tuning these small details early makes a huge difference in the reliability of your automation later.
4.9 Summary
By the end of Step 4, you’ve built a functioning automation loop a bot that can visually identify in-game objects, interact with them, and handle full inventory conditions without human input.
commands.py is now your main control script, orchestrating everything from detection to action.
This structure not only makes your bot modular but also scalable, allowing you to reuse the same logic for other skills like mining, fishing, or thieving just by changing your detection targets and image samples.
It’s the turning point where your project evolves from setup and configuration into an actual working piece of automation the first real step from concept to an intelligent, self-running script.


