Skip to main content

Godot

Welcome to your fresh Robo.js project!

Build, deploy, and maintain your Discord Activities with ease. With Robo.js as your guide, you'll experience a seamless, file-based setup, an integrated database, TypeScript support, and a rich ecosystem.

Ready to embark on this adventure?

Getting Startedโ€‹

Create a project with this template, replacing <project-name> with your desired name:

Terminal
npx create-robo <project-name> --template discord-activities/godot

Then navigate into your project directory:

Terminal
cd <project-name>

Run development mode:

Terminal
npm run dev

๏ธ App Developmentโ€‹

You can find your client-side code in the /src/app folder. This is where you can build your web app using React, Vue, or any other front-end framework.

Things are powered by Vite under the hood, so you get the latest ES modules, hot module reloading, and more! โšก

Try editing the main file to get started! (Activity.tsx if you're using React)

๐ŸŽฎ Connecting your Godot gameโ€‹

  1. Open your Godot project and add/select the Web export template.
  2. Configure the export settings for your Godot project.
    • Note if using Godot 4, you must disable Thread Support
  3. Export your Godot project as a Web build and locate the generated files. (Recommended to disable Export With Debug)
  4. Copy/Move generated files to the /public folder
    • Feel free to delete Game/Testing (it's just a demo)
    • only .js, .wasm, and .pck files required
    • .html not needed; (You can find file sizes in const GODOT_CONFIG =)
  5. update useGodot hook in src/app/Activity.tsx to point to your Godot project. example: Say my game is in public/Game/ and named Testing;
    const { startGame, loading } = useGodot('/Game/Testing', { pck: 1779104, wasm: 43016933 })
    file sizes are optional, but needed if you want progress percentage

๐Ÿงต Accessing discord sdk in Godotโ€‹

In React you pass the discord sdk to window for use in Godot

const { discordSdk, status, accessToken, session } = useDiscordSdk()
useEffect(() => {
window.discord = {
sdk: discordSdk,
accessToken,
session,
status
}
}, [discordSdk, status, accessToken, session])

In Godot, you can access the discord sdk via the JavaScriptBridge singleton

   var discord = JavaScriptBridge.get_interface("discord")

๐Ÿ”’ Authenticationโ€‹

The React template makes it easy to authenticate your activity with Discord. The <DiscordProvider> components in App.tsx accepts authenticate and scope props.

<DiscordContextProvider authenticate scope={['identify', 'guilds']}>
<Activity />
</DiscordContextProvider>

You can then get the SDK and other goodies from the useDiscordSdk hook!

๏ธ Backend Developmentโ€‹

Your server-side code is located in the /src/api folder. This is where you can build your API, webhooks, and other fancy server-side features.

This backend is powered by @robojs/server - a powerful Robo plugin that creates an manages a Node http server for you. If you install Fastify, the server will automatically switch to it for better performance!

Everything Robo is file-based, so you can create new routes by making new files in the /src/api directory. The file's name becomes the route's path. For example, let's try making a new route at /health by creating a new file named health.js:

export default () => {
return { status: 'ok' }
}

Folder Structureโ€‹

While the api and app folders are reserved for your server and client-side code, you are free to create anything else in the /src directory!

Folders only become reserved when you install a plugin that uses them. For example, bot functionality uses the commands and events folders.

Robo Ecosystemโ€‹

By building with Robo.js, you gain access to a growing ecosystem of plugins, templates, and tools. Robo Plugins are special. They can add features with one command.

Terminal
npx robo add @robojs/ai @robojs/sync

Plugins integrate seamlessly thanks to the Robo File Structure. What's more, anyone can create a plugin.

Hostingโ€‹

Hosting your project keeps it running 24/7. No need to keep your computer on at all times, or worry about your Internet connection.

You can host on any platform that supports Node.js, or run robo deploy to host on RoboPlay - a hosting platform optimized for Robo.js.

Terminal
npm run deploy

Learn Moreโ€‹

Robo.js Logo

MIT ยฉ 2024 Robo.js By WavePlay