Added new getting started guide

Thanks @MinnDevelopment for his awesome work on
the JDA guide that had no influence here at all.
This commit is contained in:
Christopher F
2017-03-11 15:32:14 -05:00
parent bea5e37db8
commit d111214bff
13 changed files with 326 additions and 42 deletions

View File

@@ -0,0 +1,15 @@
using System;
using System.Threading.Tasks;
namespace MyBot
{
public class Program
{
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
}
}
}

View File

@@ -0,0 +1,16 @@
// Program.cs
using Discord.WebSocket;
// ...
public async Task MainAsync()
{
var client = new DiscordSocketClient();
client.Log += Log;
string token = "abcdefg..."; // Remember to keep this private!
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
// Block this task until the program is closed.
await Task.Delay(-1);
}

View File

@@ -0,0 +1,42 @@
using Discord;
using Discord.WebSocket;
using System;
using System.Threading.Tasks;
namespace MyBot
{
public class Program
{
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
var client = new DiscordSocketClient();
client.Log += Log;
client.MessageReceived += MessageReceived;
string token = "abcdefg..."; // Remember to keep this private!
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
// Block this task until the program is closed.
await Task.Delay(-1);
}
private async Task MessageReceived(SocketMessage message)
{
if (message.Content == "!ping")
{
await message.Channel.SendMessageAsync("Pong!");
}
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
}
}

View File

@@ -0,0 +1,22 @@
using Discord;
using System;
using System.Threading.Tasks;
namespace MyBot
{
public class Program
{
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
}
}

View File

@@ -0,0 +1,14 @@
public async Task MainAsync()
{
// client.Log ...
client.MessageReceived += MessageReceived;
// ...
}
private async Task MessageReceived(SocketMessage message)
{
if (message.Content == "!ping")
{
await message.Channel.SendMessageAsync("Pong!");
}
}

View File

@@ -77,7 +77,6 @@ class Program
// Login and connect.
await _client.LoginAsync(TokenType.Bot, /* <DON'T HARDCODE YOUR TOKEN> */);
// Prior to rc-00608 this was ConnectAsync();
await _client.StartAsync();
// Wait infinitely so your bot actually stays connected.
@@ -96,10 +95,10 @@ class Program
await _commands.AddModuleAsync<SomeModule>();
// Subscribe a handler to see if a message invokes a command.
_client.MessageReceived += CmdHandler;
_client.MessageReceived += HandleCommandAsync;
}
private async Task CmdHandler(SocketMessage arg)
private async Task HandleCommandAsync(SocketMessage arg)
{
// Bail out if it's a System Message.
var msg = arg as SocketUserMessage;