You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
auth:'microsoft'//optional; by default uses offline mode, if using a microsoft account, set to 'microsoft'
79
+
port:25565, //set if you need a port that isn't 25565
80
+
username:'Bot', // username to join as if auth is `offline`, else a unique identifier for this account. Switch if you want to change accounts
81
+
// version: false, // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
82
+
// password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
82
83
});
83
84
84
-
client.on('chat', function(packet) {
85
+
client.on('playerChat', function (ev) {
85
86
// Listen for chat messages and echo them back.
86
-
constjsonMsg=JSON.parse(packet.message);
87
-
88
-
if (jsonMsg.translate=='chat.type.announcement'||jsonMsg.translate=='chat.type.text') {
89
-
constusername=jsonMsg.with[0].text;
90
-
constmsg=jsonMsg.with[1];
91
-
92
-
if (username ===client.username) return;
93
-
94
-
client.write('chat', {message:msg.text});
95
-
}
87
+
constcontent=ev.formattedMessage
88
+
?JSON.parse(ev.formattedMessage)
89
+
:ev.unsignedChat
90
+
?JSON.parse(ev.unsignedContent)
91
+
:ev.plainMessage
92
+
constjsonMsg=JSON.parse(packet.message)
93
+
if (ev.senderName===client.username) return
94
+
client.chat(JSON.stringify(content))
96
95
});
97
96
```
98
97
99
-
If the server is in offline mode, you may leave out the `password` option and switch auth to `offline`.
100
-
You can also leave out `password` when using a Microsoft account. If provided, password based auth will be attempted first which may fail. *Note:* if using a Microsoft account, your account age must be >= 18 years old.
98
+
Set `auth` to `offline` if the server is in offline mode. If `auth` is set to `microsoft`, you will be prompted to login to microsoft.com with a code in your browser. After signing in on your browser, the client will automatically obtain and cache authentication tokens (under your specified username) so you don't have to sign-in again.
99
+
100
+
To switch the account, update the supplied username. By default, cached tokens will be stored in your user's .minecraft folder, or if profilesFolder is specified, they'll instead be stored there. For more information on bot options see the [API doc](./API.md).
101
+
102
+
Note: SRV records will only be looked up if the port is unspecified or set to 25565 and if the `host` is a valid non-local domain name.
101
103
102
104
### Client example joining a Realm
103
105
@@ -125,7 +127,7 @@ const server = mc.createServer({
0 commit comments