First Program
This tutorial covers creating a basic ping-pong bot.
Getting the NuGet Package
It's time to grab the NuGet package, i.e. download the library so that we can use it in our code.
Stable Builds
Currently, only nightly builds are available.
Nightly Builds
Nightly builds are library builds published instantly after a commit is made to the GitHub repository, meaning that if you want to always be up-to-date you should prefer nightly builds.
They are available via the following MyGet package feed: https://www.myget.org/F/disqord/api/v3/index.json
.
Include prerelease
(or a similarly named checkbox) is checked in your IDE if you're using the MyGet package source. Install the following packages, in any order:
- Disqord.Bot
- Microsoft.Extensions.Hosting
- Serilog.Extensions.Hosting
- Serilog.Sinks.Console
Using the Library
Let's write a simple, but clean startup for our bot that can be easily expanded on later on:
using Disqord.Bot.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;
namespace MyBot
{
class Program
{
private static void Main(string[] args)
{
// The host essentially encapsulates our entire application.
using (var host = CreateHost())
{
host.Run();
}
}
private static IHost CreateHost()
{
// All host configuration goes here.
return new HostBuilder()
.UseSerilog((context, logger) =>
{
// Instructs Serilog to log into the console.
logger.WriteTo.Console();
})
.ConfigureDiscordBot((context, bot) =>
{
// Sets the bot token.
bot.Token = "YOUR_BOT_TOKEN";
// Allows ? and ! as prefixes for commands.
// By default, you can also mention the bot.
bot.Prefixes = new[] { "?", "!" };
})
.Build();
}
}
}
Press F5
(or whatever is your default keybind) to run and debug the application. You should see a log similar to:
Your bot should show up as online: