Well, the obvious problem would be the spelling mistake on the first line:
m = perhipheral.wrap("right")
which should be
m = peripheral.wrap("right")
Secondly, since I believe you can only enchant a book if it's the only one in the slot, so if you have more than one book, it won't work.
if (books > 1) then
turtle.transferTo(2, books - 1)
end
I think that was what you were trying to do with this section:
if (books > 0) then
but a. you only need to do it if there's more than 1, and b. transferTo keeps it in your inventory, instead of littering the ground.
So, all fixed up, you get something like (and via pastebin get
brY5XcT7 enchanter)
--Wraps the enchanting peripheral on the right side
m = peripheral.wrap("right")
--Sets the automatic XP collection to true
m.setAutoCollect(true)
--Sets some variables
--Variable named level
level = 0
--Variable named books based of the number of items in slot
books = turtle.getItemCount(1)
--Sets the variable level to the amount of levels the turtle has
level = m.getLevels()
--The code to enchant a book if the variable level is higher as 30
if level > 30 then
turtle.select(1)
print("level is higher as 30")
if (books > 1) then
turtle.transferTo(2, books - 1)
end
m.enchant(30)
turtle.drop()
if (books > 1) then
turtle.select(2)
turtle.transferTo(1, books - 1)
end
end
Of course, you can continue to expand it by wrapping it in a loop, so that it can collect XP. As it is, it just runs once, and if the level is not greater than 30, then it just exits.