Command for Lightning [duplicate]

I saw a friend make lightning come out of dispensers or they made it seem like it came out of dispensers. I know they used a command block.

How can I summon a lightning like that?


Solution 1:

/summon lightning_bolt ~ ~ ~

This will summon it at your current position.

Enter desired coordinates instead of tildes (~) for an specific location, or enter a number directly after each tilde to position it relative to the player/command block.

Solution 2:

From Java (computer) edition 1.11 onward the command is this:

/summon lighning_bolt [pos]

Replace [pos] with an x value, a y value, and a z value. If unspecified, it summons by you. If you put a ~ in front of the values, they are relative to your current position.

In the current Bedrock Edition (formerly Pocket Edition and console versions) the command is the same.

Source

Solution 3:

NOTE THIS: Please specify your question before asking. No one know whether it's bedrock edition or java edition.
As Stormblessed said which is used for both BE and Java:

/summon lightning_bolt[position_here]


To spawn it on all players:

/summon lightning_bolt @a


Bedrock formula:

/summon @a lightning_bolt


Replacing @a with @p, @e will result in changes:
@p :will spawn on the nearest player
@e :will spawn on all entities