Minecraft – How to use the /setblock command in minecraft to make a dispenser face west

minecraft-commandsminecraft-java-edition

I am trying to make an automated nether portal maker but I need a dispenser to face west (or any other direction that is not down) Here are some pictures of my problem:
With the regular /setblock command
With the regular /setblock command

What it should look like: (I did this manually)
What it should look like: (I did this manually)

So can anyone help me? That would be amazing. Thanks!

Best Answer

With /setblock, you specify a block's state right after its ID. You can see a block's states if you hover over it with F3 up:

F3 states

So, to make the dispenser face west:

/setblock ~ ~ ~ dispenser facing=west

If you are still on 1.10 or lower, you will instead need to use numeric data values, for which facing west is 4:

/setblock ~ ~ ~ dispenser 4