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:
15
docs/guides/samples/intro/async-context.cs
Normal file
15
docs/guides/samples/intro/async-context.cs
Normal 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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
16
docs/guides/samples/intro/client.cs
Normal file
16
docs/guides/samples/intro/client.cs
Normal 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);
|
||||
}
|
||||
42
docs/guides/samples/intro/complete.cs
Normal file
42
docs/guides/samples/intro/complete.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
22
docs/guides/samples/intro/logging.cs
Normal file
22
docs/guides/samples/intro/logging.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
14
docs/guides/samples/intro/message.cs
Normal file
14
docs/guides/samples/intro/message.cs
Normal 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!");
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user