Skip to content

Commit

Permalink
Update readme auth doc (#3169)
Browse files Browse the repository at this point in the history
Mention how auth works in readme with link to nmp API.md and 
add realm login doc from node-minecraft-protocol's readme
  • Loading branch information
extremeheat committed Aug 27, 2023
1 parent ab3c0cf commit f5d4a28
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ const mineflayer = require('mineflayer')

const bot = mineflayer.createBot({
host: 'localhost', // minecraft server ip
username: 'email@example.com', // minecraft username
username: 'Bot', // username or email, switch if you want to change accounts
auth: 'microsoft' // for offline mode servers, you can set this to 'offline'
// port: 25565, // only set if you need a port that isn't 25565
// 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
// password: '12345678' // set if you want to use password-based auth (may be unreliable)
// password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
})

bot.on('chat', (username, message) => {
Expand All @@ -97,6 +97,26 @@ bot.on('kicked', console.log)
bot.on('error', console.log)
```

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 bot will automatically obtain and cache authentication tokens in the local file system so you don't have to sign-in again.
To switch the account, update the supplied `username`. By default, cached tokens will be stored in your user's .minecraft folder.
For more information on these options and others, see node-minecraft-protocol's [API doc](https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/docs/API.md#mccreateclientoptions).

#### Connecting to a Realm

To join a Realm that your Minecraft account has been invited to, you can pass a `realms` object with a selector function like below.

```js
const client = mineflayer.createBot({
username: 'email@example.com', // minecraft username
realms: {
// This function is called with an array of Realms the account can join. It should return the one it wants to join.
pickRealm: (realms) => realms[0]
},
auth: 'microsoft'
})
```

### See what your bot is doing

Thanks to the [prismarine-viewer](https://github.com/PrismarineJS/prismarine-viewer) project, it's possible to display in a browser window what your bot is doing.
Expand Down

0 comments on commit f5d4a28

Please sign in to comment.