Rewrite all concepts documentation
hello RC documentation
This commit is contained in:
23
docs/guides/concepts/samples/connections.cs
Normal file
23
docs/guides/concepts/samples/connections.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
public class Program
|
||||
{
|
||||
private DiscordSocketClient _client;
|
||||
static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
_client = new DiscordSocketClient();
|
||||
|
||||
await _client.LoginAsync(TokenType.Bot, "bot token");
|
||||
await _client.StartAsync();
|
||||
|
||||
Console.WriteLine("Press any key to exit...");
|
||||
Console.ReadKey();
|
||||
|
||||
await _client.StopAsync();
|
||||
// Wait a little for the client to finish disconnecting before allowing the program to return
|
||||
await Task.Delay(500);
|
||||
}
|
||||
}
|
||||
13
docs/guides/concepts/samples/entities.cs
Normal file
13
docs/guides/concepts/samples/entities.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
public string GetChannelTopic(ulong id)
|
||||
{
|
||||
var channel = client.GetChannel(81384956881809408) as SocketTextChannel;
|
||||
if (channel == null) return "";
|
||||
return channel.Topic;
|
||||
}
|
||||
|
||||
public string GuildOwner(SocketChannel channel)
|
||||
{
|
||||
var guild = (channel as SocketGuildChannel)?.Guild;
|
||||
if (guild == null) return "";
|
||||
return Context.Guild.Owner.Username;
|
||||
}
|
||||
31
docs/guides/concepts/samples/events.cs
Normal file
31
docs/guides/concepts/samples/events.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
public class Program
|
||||
{
|
||||
private DiscordSocketClient _client;
|
||||
static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
|
||||
|
||||
public async Task MainAsync()
|
||||
{
|
||||
_client = new DiscordSocketClient();
|
||||
|
||||
await _client.LoginAsync(TokenType.Bot, "bot token");
|
||||
await _client.StartAsync();
|
||||
|
||||
_client.MessageUpdated += MessageUpdated;
|
||||
_client.Ready += () =>
|
||||
{
|
||||
Console.WriteLine("Bot is connected!");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
private async Task MessageUpdated(Cacheable<IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
|
||||
{
|
||||
var message = await before.GetOrDownloadAsync();
|
||||
Console.WriteLine($"{message} -> {after}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user