Skip to content
Ethan Lafrenais edited this page Apr 7, 2018 · 22 revisions

Getting Started

1. Check .NET Compatibility

Discore currently targets .NET Standard 1.5.

See the .NET Standard documentation for compatible .NET implementations.

2. Acquire Discore

Download from NuGet

Releases can be downloaded via NuGet here.

Compile from Source

The project can be built with Visual Studio 2017 (e.g. via the ".NET Core cross-platform development" workload).

3. (Optional) Try the Example Bot

If you wish to test your Discore installation, try this example bot. Just enter your bot's user token for the TOKEN constant and fire away!

using Discore;
using Discore.Http;
using Discore.WebSocket;
using System;
using System.Threading.Tasks;

namespace DiscorePingPong
{
    public class Program
    {
        DiscordHttpClient http;

        public static void Main(string[] args)
        {
            Program program = new Program();
            program.Run().Wait();
        }

        public async Task Run()
        {
            const string TOKEN = "<bot user token goes here>";

            // Create an HTTP client.
            http = new DiscordHttpClient(TOKEN);

            // Create a single shard.
            using (Shard shard = new Shard(TOKEN, 0, 1))
            {
                // Subscribe to the message creation event.
                shard.Gateway.OnMessageCreated += Gateway_OnMessageCreated;

                // Start the shard.
                await shard.StartAsync();
                Console.WriteLine("Bot started!");

                // Wait for the shard to end before closing the program.
                await shard.WaitUntilStoppedAsync();
            }
        }

        private async void Gateway_OnMessageCreated(object sender, MessageEventArgs e)
        {
            Shard shard = e.Shard;
            DiscordMessage message = e.Message;

            if (message.Author.Id == shard.UserId)
                // Ignore messages created by our bot.
                return;

            if (message.Content == "!ping")
            {
                try
                {
                    // Reply to the user who posted "!ping".
                    await http.CreateMessage(message.ChannelId, $"<@!{message.Author.Id}> Pong!");
                }
                catch (DiscordHttpApiException) { /* Message failed to send... :( */ }
            }
        }
    }
}

4. (Optional) Check out other examples

Discore has a repository dedicated to sample bots, which can be found here.

5. Start building your own bot

All that's left now is to build your bot!

See the following major sections to learn more:

Clone this wiki locally