Upto Connecting and Sending a message to a planet
This commit is contained in:
70
Guides/2.JoinPlanet.md
Normal file
70
Guides/2.JoinPlanet.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Add the bot to a Planet
|
||||
|
||||
Bots join planets the same way users do - through invite links or the Discovery page.
|
||||
<br>
|
||||
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](https://skyjoshua.xyz/planetjoiner)
|
||||
<br>
|
||||
You should see something like this below:
|
||||
<br>
|
||||

|
||||
<br>
|
||||
Fill in the boxes with the required information and hit **Join Planet** and the bot should join the desired planet.
|
||||
<br>
|
||||
*Note: Sometimes the Invite Cote 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.
|
||||
|
||||
```c#
|
||||
// If the planet is open to discovery only the planet ID is required.
|
||||
await client.PlanetService.JoinPlanetAsync(planetId);
|
||||
```
|
||||
or
|
||||
```c#
|
||||
// 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.)
|
||||
|
||||
```c#
|
||||
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](3.ConnectingAndSending.md)
|
||||
Reference in New Issue
Block a user