Browse Source

Clarify several guides samples with notes

- Reword TypeReader comment to avoid giving the idea that the sample itself is "obsolete"
- Remove CommandException logging comment regarding C#7.0 as the version is now the standard across VS2017 and up
- Remove suggestion about handling result in command handler since it is now advised to use CommandExecuted instead
+ Add additional comment to clarify ctor for DI setup
pull/1304/head
Still Hsu 6 years ago
parent
commit
5b275f6688
4 changed files with 8 additions and 14 deletions
  1. +3
    -0
      docs/guides/commands/samples/dependency-injection/dependency_map_setup.cs
  2. +2
    -11
      docs/guides/commands/samples/intro/command_handler.cs
  3. +0
    -1
      docs/guides/commands/samples/post-execution/command_exception_log.cs
  4. +3
    -2
      docs/guides/commands/samples/typereaders/typereader.cs

+ 3
- 0
docs/guides/commands/samples/dependency-injection/dependency_map_setup.cs View File

@@ -3,6 +3,9 @@ public class Initialize
private readonly CommandService _commands; private readonly CommandService _commands;
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;


// Ask if there are existing CommandService and DiscordSocketClient
// instance. If there are, we retrieve them and add them to the
// DI container; if not, we create our own.
public Initialize(CommandService commands = null, DiscordSocketClient client = null) public Initialize(CommandService commands = null, DiscordSocketClient client = null)
{ {
_commands = commands ?? new CommandService(); _commands = commands ?? new CommandService();


+ 2
- 11
docs/guides/commands/samples/intro/command_handler.cs View File

@@ -3,6 +3,7 @@ public class CommandHandler
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
private readonly CommandService _commands; private readonly CommandService _commands;


// Retrieve client and CommandService instance via ctor
public CommandHandler(DiscordSocketClient client, CommandService commands) public CommandHandler(DiscordSocketClient client, CommandService commands)
{ {
_commands = commands; _commands = commands;
@@ -46,19 +47,9 @@ public class CommandHandler


// Execute the command with the command context we just // Execute the command with the command context we just
// created, along with the service provider for precondition checks. // created, along with the service provider for precondition checks.
// Keep in mind that result does not indicate a return value
// rather an object stating if the command executed successfully.
var result = await _commands.ExecuteAsync(
await _commands.ExecuteAsync(
context: context, context: context,
argPos: argPos, argPos: argPos,
services: null); services: null);

// Optionally, we may inform the user if the command fails
// to be executed; however, this may not always be desired,
// as it may clog up the request queue should a user spam a
// command.
// if (!result.IsSuccess)
// await context.Channel.SendMessageAsync(result.ErrorReason);
} }
} }

+ 0
- 1
docs/guides/commands/samples/post-execution/command_exception_log.cs View File

@@ -1,6 +1,5 @@
public async Task LogAsync(LogMessage logMessage) public async Task LogAsync(LogMessage logMessage)
{ {
// This casting type requries C#7
if (logMessage.Exception is CommandException cmdException) if (logMessage.Exception is CommandException cmdException)
{ {
// We can tell the user that something unexpected has happened // We can tell the user that something unexpected has happened


+ 3
- 2
docs/guides/commands/samples/typereaders/typereader.cs View File

@@ -1,5 +1,6 @@
// Note: This example is obsolete, a boolean type reader is bundled
// with Discord.Commands
// Please note that the library already supports type reading
// primitive types such as bool. This example is merely used
// to demonstrate how one could write a simple TypeReader.
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;




Loading…
Cancel
Save