Update sample projects & samples in docs (#2823)

* update them all

* more docs

* moar docs
This commit is contained in:
Mihail Gribkov
2024-01-11 18:25:56 +03:00
committed by GitHub
parent 8227d70b86
commit e2e8c0fd6a
31 changed files with 732 additions and 806 deletions

View File

@@ -1,8 +1,6 @@
public class Program
{
public static Task Main(string[] args) => new Program().MainAsync();
public async Task MainAsync()
public static async Task Main()
{
}
}

View File

@@ -1,6 +1,6 @@
private DiscordSocketClient _client;
private static DiscordSocketClient _client;
public async Task MainAsync()
public static async Task Main()
{
_client = new DiscordSocketClient();

View File

@@ -1,10 +1,8 @@
public class Program
{
private DiscordSocketClient _client;
private static DiscordSocketClient _client;
public static Task Main(string[] args) => new Program().MainAsync();
public async Task MainAsync()
public async Task Main()
{
_client = new DiscordSocketClient();
_client.Log += Log;

View File

@@ -1,4 +1,4 @@
private Task Log(LogMessage msg)
private static Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;

View File

@@ -1,11 +1,11 @@
public async Task MainAsync()
public static async Task Main()
{
// ...
_client.MessageReceived += MessageReceived;
// ...
}
private async Task MessageReceived(SocketMessage message)
private static async Task MessageReceived(SocketMessage message)
{
if (message.Content == "!ping")
{

View File

@@ -10,21 +10,7 @@ using Discord.WebSocket;
class Program
{
// Program entry point
static Task Main(string[] args)
{
// Call the Program constructor, followed by the
// MainAsync method and wait until it finishes (which should be never).
return new Program().MainAsync();
}
private readonly DiscordSocketClient _client;
// Keep the CommandService and DI container around for use with commands.
// These two types require you install the Discord.Net.Commands package.
private readonly CommandService _commands;
private readonly IServiceProvider _services;
private Program()
static async Task Main(string[] args)
{
_client = new DiscordSocketClient(new DiscordSocketConfig
{
@@ -58,8 +44,14 @@ class Program
// Setup your DI container.
_services = ConfigureServices();
}
private static DiscordSocketClient _client;
// Keep the CommandService and DI container around for use with commands.
// These two types require you install the Discord.Net.Commands package.
private static CommandService _commands;
private static IServiceProvider _services;
// If any services require the client, or the CommandService, or something else you keep on hand,
// pass them as parameters into this method as needed.
@@ -110,7 +102,7 @@ class Program
return Task.CompletedTask;
}
private async Task MainAsync()
private static async Task MainAsync()
{
// Centralize the logic for commands into a separate method.
await InitCommands();
@@ -125,7 +117,7 @@ class Program
await Task.Delay(Timeout.Infinite);
}
private async Task InitCommands()
private static async Task InitCommands()
{
// Either search the program and add all Module classes that can be found.
// Module classes MUST be marked 'public' or they will be ignored.
@@ -140,7 +132,7 @@ class Program
_client.MessageReceived += HandleCommandAsync;
}
private async Task HandleCommandAsync(SocketMessage arg)
private static async Task HandleCommandAsync(SocketMessage arg)
{
// Bail out if it's a System Message.
var msg = arg as SocketUserMessage;

View File

@@ -7,11 +7,11 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="2.0.0" />
<PackageReference Include="Discord.Net" Version="3.13.0" />
</ItemGroup>
</Project>