Commands/scriptevent
Minecraft Wiki article. Categories: Bedrock_Edition, Minecraft_Education, Commands
📌 Mirrored from Minecraft Wiki
This article is reproduced from Commands/scriptevent on the Minecraft Wiki. Mirrored from revision 3619573. It is licensed CC BY-NC-SA 3.0 by the Minecraft Wiki contributors — not under the Codex’s CC BY-SA 4.0, and it may not be used commercially. Edits belong upstream, not here.
On this page
This feature is exclusive to Bedrock Edition and Minecraft Education.
/scriptevent{
"title": "<code>/scriptevent</code>",
"rows": [
{
"field": "1",
"label": "(link to Permission level article, displayed as Permission level<br>required)"
},
{
"field": "(link to Cheat article, displayed as Cheat) only<br>",
"label": "(link to Commands#Restrictions article, displayed as Restrictions)"
}
],
"invimages": [],
"images": []
}
Triggers a script event with an ID and message.
Syntax
scriptevent <messageId: string> <message: message>
Arguments
messageId: string: basic_string
- Must be a string. Must be namespaced and use of the minecraft namespace is invalid (e.g.
/scriptevent give:coal,/scriptevent my_scripts:spawn_sheep)
message: message: CommandMessage
- Optional argument. Maximum length is the C++ max string length. It is a greedy phrase string argument (taking the rest of the command as the string argument). Can include spaces as well as target selectors. The game replaces entity selectors in the message with the list of selected entities' names, which is formatted as "name1 and name2" for two entities, or "name1, name2, ... and namen" for n entities.
@<player name>can be used to mention a player;@herecan be used to mention all players.
Result
| Command | Trigger | Bedrock Edition |
|---|---|---|
| Any | the arguments are not specified correctly | Unparseable |
| Otherwise | Successful |
The command by itself does not directly affect anything in the game, but can trigger an event in any add-ons applied to the world/server.
Output
| Command | Edition | Situation | Success Count |
|---|---|---|---|
| any | Bedrock Edition | On fail | 0 |
| On success | 1 |
Example
- To evoke an event handler with the ID wiki:example and the message "Example Message":
/scriptevent wiki:example Example Message
- Example JavaScript code for use in the scripting API:
import { system } from "@minecraft/server";
system.afterEvents.scriptEventReceive.subscribe((event) => {
const {
id, // returns string (wiki:example)
initiator, // returns Entity
message, // returns string (Example Message)
sourceBlock, // returns Block
sourceEntity, // returns Entity
sourceType, // returns MessageSourceType
} = event;
});
History
| Bedrock Edition | |||||||
|---|---|---|---|---|---|---|---|
| Beta APIs (Experimental) | Preview 1.19.60.22 | Added /scriptevent behind the "Beta APIs" experimental toggle. | |||||
| 1.20.30 | Preview 1.20.20.20 | /scriptevent is no longer behind "Beta APIs" experimental toggle. | |||||
See also
/script— debugging options for GameTest Framework
External links
- "
/scripteventCommand" – Microsoft Learn, December 12, 2024.
Navigation
Sources
- Commands/scriptevent — Minecraft Wiki, CC BY-NC-SA 3.0, revision 3619573.