And it will never print that it is at bedrock because the function
turtle.down always exists, and that is all you're checking.
This is how you would need to do it
local function down()
while not turtle.down() do
if turtle.detectDown() then --# it couldn't move because of a block
if not turtle.digDown() then --# it couldn't dig a block, assume it is a diamond axe, and a the only thing that cannot be dug is bedrock.
print("bedrock")
end
elseif turtle.attack() then --# it couldn't move because of a mob
while turtle.attack() do end
elseif turtle.getFuelLevel() == 0 then --# it couldn't move because of no fuel
--# refuel it
end
end
end