Update sample projects & samples in docs (#2823)
* update them all * more docs * moar docs
This commit is contained in:
@@ -3,10 +3,8 @@ using Discord.WebSocket;
|
||||
|
||||
public class Program
|
||||
{
|
||||
private DiscordSocketClient _client;
|
||||
static void Main(string[] args) => new Program().MainAsync().GetAwaiter().GetResult();
|
||||
|
||||
public async Task MainAsync()
|
||||
private static DiscordSocketClient _client;
|
||||
public static async Task MainAsync()
|
||||
{
|
||||
// When working with events that have Cacheable<IMessage, ulong> parameters,
|
||||
// you must enable the message cache in your config settings if you plan to
|
||||
@@ -27,7 +25,7 @@ public class Program
|
||||
await Task.Delay(-1);
|
||||
}
|
||||
|
||||
private async Task MessageUpdated(Cacheable<IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
|
||||
private static async Task MessageUpdated(Cacheable<IMessage, ulong> before, SocketMessage after, ISocketMessageChannel channel)
|
||||
{
|
||||
// If the message was not in the cache, downloading it will result in getting a copy of `after`.
|
||||
var message = await before.GetOrDownloadAsync();
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
public class Program
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public Program()
|
||||
{
|
||||
_serviceProvider = CreateProvider();
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
=> new Program().RunAsync(args).GetAwaiter().GetResult();
|
||||
|
||||
private static IServiceProvider _serviceProvider;
|
||||
|
||||
static IServiceProvider CreateProvider()
|
||||
{
|
||||
var collection = new ServiceCollection();
|
||||
@@ -17,8 +9,8 @@ public class Program
|
||||
return collection.BuildServiceProvider();
|
||||
}
|
||||
|
||||
async Task RunAsync(string[] args)
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
//...
|
||||
_serviceProvider = CreateProvider();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
private DiscordSocketClient _client;
|
||||
private static DiscordSocketClient _client;
|
||||
|
||||
public async Task MainAsync()
|
||||
public static async Task Main()
|
||||
{
|
||||
_client = new DiscordSocketClient();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
private Task Log(LogMessage msg)
|
||||
private static Task Log(LogMessage msg)
|
||||
{
|
||||
Console.WriteLine(msg.ToString());
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -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")
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user