Skip to content
Ethan Lafrenais edited this page Jan 7, 2017 · 22 revisions

Getting Started

Pre-built Downloads

Pre-built releases can be downloaded via NuGet here.

Compile from Source

If you want to work with the latest unreleased version of Discore you will need:

  • Visual Studio 2015 with Update 3
  • .NET Core 1.0.1 tools Preview 2

Which can be obtained here.

OR

Choose your type of Discord application

Example Bot: Ping Pong

using Discore;
using Discore.WebSocket;
using System;
using System.Threading;

namespace DiscorePingPong
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // Create authenticator using a bot user token.
            DiscordBotUserToken token = new DiscordBotUserToken("<bot user token goes here>");

            // Create a WebSocket application.
            DiscordWebSocketApplication app = new DiscordWebSocketApplication(token);

            // Create and start a single shard.
            Shard shard = app.ShardManager.CreateSingleShard();
            shard.Start();

            // Subscribe to the message creation event.
            shard.Gateway.OnMessageCreated += Gateway_OnMessageCreated;

            // Wait for the shard to end before closing the program.
            while (shard.IsRunning)
                Thread.Sleep(100);
        }

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

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

            if (message.Content == "!ping")
            {
                // Grab the DM or guild text channel this message was posted in from cache.
                ITextChannel textChannel = (ITextChannel)shard.Cache.Channels.Get(message.ChannelId);

                try
                {
                    // Reply to the user who posted "!ping".
                    await textChannel.SendMessage($"<@{message.Author.Id}> Pong!");
                }
                catch (Exception) {  /* Message failed to send... :( */ }
            }
        }
    }
}
Clone this wiki locally