Welcome to Fluxer.Net! This guide will walk you through creating your first bot using the Fluxer.Net library.
First, create a new console application and install the Fluxer.Net package:
dotnet new console -n MyFluxerBot
cd MyFluxerBot
dotnet add package Fluxer.Net
To connect your bot to Fluxer, you'll need an authentication token. There are two types of tokens you can use:
User tokens allow your bot to act as a regular user account. To obtain a user token:
token key and copy its valueWarning: Never share your token with anyone. Anyone with your token can access your account.
Now let's write the code to connect to Fluxer. Open Program.cs and replace its contents with:
using Fluxer.Net;
using Serilog;
// Configure logging
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information()
.WriteTo.Console()
.CreateLogger();
// Your Fluxer token
const string token = "YOUR_TOKEN_HERE";
// Create configuration
var config = new FluxerConfig
{
Serilog = Log.Logger,
EnableRateLimiting = true
};
// Create the clients
var apiClient = new ApiClient(token, config);
var gatewayClient = new GatewayClient(token, config);
// Connect to the gateway
await gatewayClient.ConnectAsync();
Log.Information("Bot is running! Press Ctrl+C to exit.");
// Keep the application running
await Task.Delay(-1);
Replace YOUR_TOKEN_HERE with your actual token, then run:
dotnet run
You should see log messages indicating that your bot has successfully connected to Fluxer!
Your bot is now connected, but it doesn't do anything yet. In the next tutorial, we'll learn how to receive and respond to messages.