Files
Valour-Bot-Guide/Guides/2.JoinPlanet.md

2.0 KiB

Add the bot to a Planet

Bots join planets the same way users do - through invite links or the Discovery page.
There are a few way of doing this. I will be going through two of them in this guide.

1. Using my website

The easiest way to add a bot to your Planet is to use my website here
You should see something like this below:
Planet Joiner Site
Fill in the boxes with the required information and hit Join Planet and the bot should join the desired planet.
Note: Sometimes the Invite Code is not required if the Planet you are trying to join is Discoverable

2. Using code

To make a Bot join your Planet using code we can add 1 line to the previous code.

// If the planet is open to discovery only the planet ID is required.
await client.PlanetService.JoinPlanetAsync(planetId);

or

// If the planet is not open to discovery an the last part of an invite (the invite code) is also required.
await client.PlanetService.JoinPlanetAsync(planetId, "INVITE_CODE");

Below is the full code required to add the bot to a planet. (Comments are new parts added.)

using Valour.Sdk.Client;
using Valour.Shared;
using DotNetEnv;

ValourClient client = new ValourClient("https://api.valour.gg/");
client.SetupHttpClient();

Env.Load();

string token = Environment.GetEnvironmentVariable("TOKEN") ?? string.Empty;

if (string.IsNullOrWhiteSpace(token)) 
{
    Console.WriteLine($"Token invalid. Please make sure you set a valid token in your .env");
    return;
}

TaskResult loginResult = await client.InitializeUser(token);
if (!loginResult.Success)
{
    Console.WriteLine($"Login failed: {loginResult.Message}");
}

Console.WriteLine($"Logged in as {client.Me.Name} (ID: {client.Me.Id})");


// Join a planet
await client.PlanetService.JoinPlanetAsync(00000000000000000, "ABCDEF");


await Task.Delay(Timeout.Infinite);

The Next step is to Connecting and Sending a message to a Planet