First add an event inside of the main function. You need to add a function reference (to checkInventory) and a “player_chat Event” (NOTE: this event can be changed to something else, depending on how you want to trigger the checkInventory function).
The function that you reference (checkInventory) needs to have a parameter (in this case info), this will allow the code to retrieve information from the event. Inside of this new function you will need to check if the message that was chatted was check; do this by getting an if statement and checking if "info's Message = 'check'".
If that returns true you need to create and set three new variables: set "user" to "info's Player" to retrieve who chatted, then set "playerInventory" to "user's Inventory" to retrieve the inventory of that player, and finally set "inventoryContents" to "playerInventory's Contents" to retrieve the list of items in the inventory.
Next you have to loop through each item of the list and check each time if the current item is the one you're looking for (NOTE: if the current slot is empty [null] it has to skipped and check the next slot [continue with next iteration]). Make sure you look carefully at the image below, there is an inner if statement in the else section of the outer if statement; and you need to check "i's Type" which is the type of item/block in that current slot.
This mod checks the player's inventory when they chat "check", and prints out "The player has a Diamond Sword" if it finds one in their inventory.