Skip to content

This repository offers a library for sending messages and embeds from a Bedrock Dedicated Server (BDS) to Discord.

License

Notifications You must be signed in to change notification settings

Esploratori-Dev/bedrock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BridgeDirect

This repository offers a library for sending messages and embeds from a Bedrock Dedicated Server (BDS) to Discord.

Note

This class is intended to be used inside a Minecraft Bedrock scripting addon. Despite the class being able to run on any minecraft world, it will work only when run along with BedrockBridge, which is currently available for bds server (and not realms or local worlds).

Note

This library works for all BedrockBridge versions since v1.4.2, which runs on Minecraft Bedrock Edition v1.21.30. Previous versions are not supported.

What does the library do?

With this library you have access to a BridgeDirect instance. A simple class that handles sending messages to BedrockBridge through scriptevents. BedrockBridge will handle the discord connection part.

How to use it?

You can either copy the code of the class to your project, or install the npm package and then bundle your pack.

import { bridgeDirect } from "@esploratori/bedrock";

bridgeDirect.events.directInitialize.subscribe(() => {

    bridgeDirect.sendMessage("Welcome from bedrock!")

})

If you copy the file, the first line of this code will probably look like this import { bridgeDirect } from "./index.js".

direct_example

Be careful when using the library that the directInitialize event has been sent, otherwise trying to send messages will result in an error.

  1. A possible approach to this problem could be checking if the connection is ready before sending logs.
// ...
import { world } from "@minecraft/server"

world.afterEvents.itemUse.subscribe(e=>{
    if (e.itemStack.nameTag==="legendary-item"){

        if (bridgeDirect.ready){ // making sure that the bridge is active
            bridgeDirect.sendMessage(e.source.name + " used a legendary item", "Legendary News")
        }
    }
})
  1. While another approach could be including your pack logic inside the bridgeInitialize event.
// ...
bridgeDirect.events.directInitialize.subscribe(()=>{

    world.afterEvents.itemUse.subscribe(e => {
        if (e.itemStack.nameTag === "legendary-item") {
            bridgeDirect.sendMessage(e.source.name + " used a legendary item", "Legendary News")
        }
    })
    
})

Of course which solution to use depends on the purpose of your pack. If your pack wants to provide additional discord capabilities to a well pre-established in-game mechanic then it would make sense to use the first solution. If you are developing a pack mostly focused on the discord connection then probably the second solution is preferable.

It is however advisable to handle the connection delay, or the possibility that BedrockBridge is not installed, by e.g. caching the messages untill the bridge is ready, or sending logs to the users if the connection hasn't been established for a long time (which means that there is something wrong). A typical setup delay would be 2-5 seconds.

Important

BridgeDirect capabilities are not enabled by default on the BedrockBridge addon. They need to be enabled with a bridge-plugin. We created a dedicated release of the pack with such addition already enabled marked as Direct. Make sure to download the right version, or handle enabling direct-addition yourself.

Releasing your addon

Here comes the sensitive part. This library is opensource. It can be used, copied, included in your addon and modified without restrictions. However it's not the same for BedrockBridge. You can add a link to our download page on your page.

Warning

You cannot include BedrockBridge in your pack or add a direct download link to BedrockBridge.