From f81af0bdd14f4eec9f92116bbbcb373665a34527 Mon Sep 17 00:00:00 2001 From: Hsu Still <341464@gmail.com> Date: Wed, 28 Mar 2018 02:51:16 +0800 Subject: [PATCH] Add Overwrites files for some classes + Starting from this commit, there will be overwrite files added to provide further details about certain APIs. --- .../Commands/CommandException.Overwrite.md | 27 ++++++++++++++++++ .../DontAutoLoadAttribute.Overwrite.md | 20 +++++++++++++ .../Commands/DontInjectAttribute.Overwrite.md | 26 +++++++++++++++++ .../ShardedCommandContext.Overwrite.md | 10 +++++++ .../Common/Discord.EmbedBuilder.Overwrites.md | 28 +++++++++++++++++++ 5 files changed, 111 insertions(+) create mode 100644 docs/_overwrites/Commands/CommandException.Overwrite.md create mode 100644 docs/_overwrites/Commands/DontAutoLoadAttribute.Overwrite.md create mode 100644 docs/_overwrites/Commands/DontInjectAttribute.Overwrite.md create mode 100644 docs/_overwrites/Commands/ShardedCommandContext.Overwrite.md create mode 100644 docs/_overwrites/Common/Discord.EmbedBuilder.Overwrites.md diff --git a/docs/_overwrites/Commands/CommandException.Overwrite.md b/docs/_overwrites/Commands/CommandException.Overwrite.md new file mode 100644 index 000000000..a5a713bcb --- /dev/null +++ b/docs/_overwrites/Commands/CommandException.Overwrite.md @@ -0,0 +1,27 @@ +--- +uid: Discord.Commands.CommandException +--- + +### Remarks + +This @System.Exception class is typically used when diagnosing +an error thrown during the execution of a command. You will find the +thrown exception passed into +[LogMessage.Exception](xref:Discord.LogMessage.Exception), which is +sent to your [CommandService.Log](xref:Discord.Commands.CommandService.Log) +event handler. + +You may use this information to handle runtime exceptions after +execution. Below is an example of how you may use this: + +```cs +public Task LogHandlerAsync(LogMessage logMessage) +{ + // Note that this casting method requires C#7 and up. + if (logMessage?.Exception is CommandException cmdEx) + { + Console.WriteLine($"{cmdEx.GetBaseException().GetType()} was thrown while executing {cmdEx.Command.Aliases.First()} in {cmdEx.Context.Channel} by {cmdEx.Context.User}."); + } + return Task.CompletedTask; +} +``` \ No newline at end of file diff --git a/docs/_overwrites/Commands/DontAutoLoadAttribute.Overwrite.md b/docs/_overwrites/Commands/DontAutoLoadAttribute.Overwrite.md new file mode 100644 index 000000000..857e05cf8 --- /dev/null +++ b/docs/_overwrites/Commands/DontAutoLoadAttribute.Overwrite.md @@ -0,0 +1,20 @@ +--- +uid: Discord.Commands.DontAutoLoadAttribute +--- + +### Remarks + +The attribute can be applied to a public class that inherits +@Discord.Commands.ModuleBase. By applying this attribute, +@Discord.Commands.CommandService.AddModulesAsync* will not discover and +add the marked module to the CommandService. + +### Example + +```cs +[DontAutoLoad] +public class MyModule : ModuleBase +{ + // ... +} +``` \ No newline at end of file diff --git a/docs/_overwrites/Commands/DontInjectAttribute.Overwrite.md b/docs/_overwrites/Commands/DontInjectAttribute.Overwrite.md new file mode 100644 index 000000000..ed59c6ced --- /dev/null +++ b/docs/_overwrites/Commands/DontInjectAttribute.Overwrite.md @@ -0,0 +1,26 @@ +--- +uid: Discord.Commands.DontInjectAttribute +--- + +### Remarks + +The attribute can be applied to a public settable property inside a +@Discord.Commands.ModuleBase based class. By applying this property, +the marked property will not be automatically injected of the +dependency. See [Dependency Injection](../../guides/commands/commands.md#dependency-injection) +to learn more. + +### Example + +```cs +public class MyModule : ModuleBase +{ + [DontInject] + public MyService MyService { get; set; } + + public MyModule() + { + MyService = new MyService(); + } +} +``` \ No newline at end of file diff --git a/docs/_overwrites/Commands/ShardedCommandContext.Overwrite.md b/docs/_overwrites/Commands/ShardedCommandContext.Overwrite.md new file mode 100644 index 000000000..f3c5bacbc --- /dev/null +++ b/docs/_overwrites/Commands/ShardedCommandContext.Overwrite.md @@ -0,0 +1,10 @@ +--- +uid: Discord.Commands.ShardedCommandContext +--- + +### Example +An example of how this class is used the command system can be seen +below: + +[!code[Sample module](../../guides/commands/samples/empty-module.cs)] +[!code[Command handler](../../guides/commands/samples/command_handler.cs)] \ No newline at end of file diff --git a/docs/_overwrites/Common/Discord.EmbedBuilder.Overwrites.md b/docs/_overwrites/Common/Discord.EmbedBuilder.Overwrites.md new file mode 100644 index 000000000..1a7fcd9bb --- /dev/null +++ b/docs/_overwrites/Common/Discord.EmbedBuilder.Overwrites.md @@ -0,0 +1,28 @@ +--- +uid: Discord.EmbedBuilder +--- + +### Remarks + +This builder class is used to build an @Discord.Embed (rich embed) +object that will be ready to be sent via @Discord.IMessageChannel.SendMessageAsync* +after @Discord.EmbedBuilder.Build* is called. + +### Example + +```cs +public async Task SendRichEmbedAsync() +{ + var embed = new EmbedBuilder + { + // Embed property can be set within object initializer + Title = "Hello world!" + } + // Or with the method + .WithTitle("I overwrote the title.") + .WithDescription("I am a description.") + .WithUrl("https://example.com") + .Build(); + await _channel.SendMessageAsync(string.Empty, embed: embed); +} +``` \ No newline at end of file