Browse Source

Add Overwrites files for some classes

+	Starting from this commit, there will be overwrite files added to
	provide further details about certain APIs.
pull/988/head
Hsu Still 7 years ago
parent
commit
f81af0bdd1
5 changed files with 111 additions and 0 deletions
  1. +27
    -0
      docs/_overwrites/Commands/CommandException.Overwrite.md
  2. +20
    -0
      docs/_overwrites/Commands/DontAutoLoadAttribute.Overwrite.md
  3. +26
    -0
      docs/_overwrites/Commands/DontInjectAttribute.Overwrite.md
  4. +10
    -0
      docs/_overwrites/Commands/ShardedCommandContext.Overwrite.md
  5. +28
    -0
      docs/_overwrites/Common/Discord.EmbedBuilder.Overwrites.md

+ 27
- 0
docs/_overwrites/Commands/CommandException.Overwrite.md View File

@@ -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;
}
```

+ 20
- 0
docs/_overwrites/Commands/DontAutoLoadAttribute.Overwrite.md View File

@@ -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<SocketCommandContext>
{
// ...
}
```

+ 26
- 0
docs/_overwrites/Commands/DontInjectAttribute.Overwrite.md View File

@@ -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<SocketCommandContext>
{
[DontInject]
public MyService MyService { get; set; }

public MyModule()
{
MyService = new MyService();
}
}
```

+ 10
- 0
docs/_overwrites/Commands/ShardedCommandContext.Overwrite.md View File

@@ -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)]

+ 28
- 0
docs/_overwrites/Common/Discord.EmbedBuilder.Overwrites.md View File

@@ -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);
}
```

Loading…
Cancel
Save