Explain how I create a discord bot for Minecraft bedrock on docker. No explanation on docker while be done here but there is a lot of tutorial for installing docker on server.
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5246641c80da itzg/minecraft-bedrock-server "/usr/local/bin/entr…" 3 hours ago Up 39 minutes (healthy) 0.0.0.0:19132->19132/udp Minecraft
to interact with the server you need to do:
1 2 3 4 5
$ docker attach Minecraft DEBU[2562] Forwarding signal signal="window changed" DEBU[2562] Forwarding signal signal="window changed" list There are 0/5 players online:
if message.content.startswith('!stats'): stream = os.popen('docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" Minecraft') out = stream.read() await message.channel.send(out)
if message.content.startswith('!setDay'): os.popen('screen -S Minecraft -p 0 -X stuff "time set day^M"') await message.channel.send('set time to [day]')
if message.content.startswith('!setNight'): os.popen('screen -S Minecraft -p 0 -X stuff "time set night^M"') await message.channel.send('set time to [night]')
if message.content.startswith('!normal'): os.popen('screen -S Minecraft -p 0 -X stuff "difficulty normal^M"') await message.channel.send('set difficulty to [normal]')
if message.content.startswith('!hard'): os.popen('screen -S Minecraft -p 0 -X stuff "difficulty hard^M"') await message.channel.send('set difficulty to [hard]')
if message.content.startswith('!thunder'): os.popen('screen -S Minecraft -p 0 -X stuff "weather thunder^M"') await message.channel.send('set weather to [thunder]')
if message.content.startswith('!sun'): os.popen('screen -S Minecraft -p 0 -X stuff "weather clear^M"') await message.channel.send('set weather to [clear]')
if message.content.startswith('!help'): msg = "Prefix cmd with <!> \nserver : show server info \nstats : show server stat \nsetDay : set day \nsetNight : set night \nnormal : set difficulty to normal \nhard : set difficulty to hard \nthunder : set weather to thunder \nsun : set weather to sun\nopAdmin : set User operator \ndeOpAdmin : remove User operator \ncreativeAdmin : set creative mode to User \nsurvieAdmin : set survie mode to User" await message.channel.send(msg)
#msg = "Message from Server {}".format(msgFromServer[0]) data = msgFromServer[0][35:].decode("utf-8") indexes = ['Game','ServerName','ProtocolVersion','ServerVersion','PlayerCount','PlayerLimit','ServerId','WorldName','GameMode','NintendoLimited','Ipv4Port','Ipv6Port'] datas = data[:-1].split(';') out = {} for i inrange(len(indexes)): out[indexes[i]] = datas[i]
return out #return json.dumps(out)
if __name__ == '__main__':
print(bdsPing(server,port))
To run the bot in background start it in a screen session.