Step 1: Let's start by opening the Minecraft folder. To open it, press the Windows key and R at the same time, or if you prefer, just type run in the search bar.
I don't know how to open it on Mac or Linux; check elsewhere how to open the folder on these systems.
Continuing, as soon as the Run window opens, type %appdata% and press Enter.
Look for the .minecraft folder (it's usually at the top of the page) and then open the saves folder.
Select the folder of the world where you want to set up the functions.
Your world will have several folders; look for the datapacks folder and open it.
Step 2: When you get to the datapacks folder, it will probably be empty. I have already prepared the necessary subfolders to make things easier, and inside, there is a ready-to-use function.
Now download this ready folder drag it into the datapacks folder and extract the .rar file.

I chose to extract it with WinRAR, and I recommend installing it on your computer.
Once you're done extracting, delete the .rar file.
You can name this folder whatever you like. Notice that inside it, there are other folders — I'll explain more about that.
Step 3: Notice that we have the comandos folder inside the data folder. You can change the name of the comandos folder to anything, but remember, this will affect how you call the function in Minecraft.
Inside the comandos folder, we have the function folder. This is where your functions will go. Notice that I left a ready-made function inside.
You can copy and paste this file to change its name.
Open it with Notepad or Notepad++ and start adding your commands.
Very important! Always test your commands before putting them there,
because any command errors will prevent the function from loading in Minecraft.
Step 4: Let's call the function inside Minecraft.

When I start typing the name of the comandos folder, the functions appear.
This is a sign that everything is working, including the commands inside these functions.