docs: Documentation December Update (#1218)
* Fix broken link (#11) * Fix typos and improve wording * Add information for IGuildUser + Add GetPermission sample + Add ModifyAsync remarks * Add information for IGuildChannel + Add ModifyAsync remarks + Add GetOverwritePermissionAsync examples * Add warning for Direction.Around * Fix indentations and references * Move IRole.ModifyAsync sample * Add information for IUser + Add example, remarks for Get(Default)AvatarUrl + Add example, remarks for GetOrCreateDMChannelAsync + Add missing remarks/summary/returns for other properties of the class * Change verbs used in IVoiceState summary/remarks * Add additional explanation for IGuildUser.RoleIds * Change verbs used in IMessage summary/remarks * Clarify IUserMessage Add/RemoveReactionAsync samples * Fix command handler sample typo * Add information for DiscordSocketConfig + Add remarks/example to the class + Add remarks to AlwaysDownloadUsers * Fix documentation for SlowMode * Add additional remarks for Guild/TextChannelProperties * Update DocFx.Plugins.LastModified to v1.2.0 This should drastically improve docfx build time. * Add missing dependencies * Update DocFx.Plugins.LastModified to v1.2.1 Improve performance * Update DocFx.Plugins.LastModified to v1.2.2 * Clarify deployment.md + Rewritten .NET Core deployment strategies for better clarification * Split deployment types into framework-dependent and self-contained * Clarify the benefits of using different types of publishing * Include a sample of how to execute dotnet application with the dotnet command in a TIP dialog for visibility * Update post-execution article and samples + This change is to reflect changes made in https://github.com/RogueException/Discord.Net/pull/1164, where CommandInfo is now passed into the CommandExecuted event as an Optional<T> * Update DocFX.Plugin.DescriptionGenerator to v1.1.1 * Adjust according to recent CommandExecuted changes See: +f549da50e0+6260749095* Add further documentation for https://github.com/RogueException/Discord.Net/pull/1037 * Add partial documentation for the precondition helper class * Include CHANGELOG.md in docs * Revise post-execution docs * Fix incorrect Optional<T> usage * Indent some sample code and add a comment reminding the user that the post-execution basic sample code is not ideal. * Streamline docs for Attachment + This commit also adds further explanation for why Embeds and Attachments are read-only collections * Add further documentation for MessageActivity and MessageApplication * Add caching-related docs to ISocketMessageChannel * Add missing documentation inheritance for SyncPermissionsAsync * Streamline documentation process This is done by changing the documentation of the implementations required by interfaces to redirect to the interface method instead (e.g., SocketDMChannel#GetMessagesAsync refer to IMessageChannel.GetMessagesAsync within the remarks of the method). * Cleanup92bf8363ca* Update src/Discord.Net.Core/Entities/Channels/Direction.cs Co-Authored-By: Still34 <341464@gmail.com> * Update src/Discord.Net.Core/Entities/Channels/Direction.cs Co-Authored-By: Still34 <341464@gmail.com> * Update src/Discord.Net.Core/Entities/Channels/GuildChannelProperties.cs Co-Authored-By: Still34 <341464@gmail.com> * Update src/Discord.Net.WebSocket/DiscordSocketConfig.cs Co-Authored-By: Still34 <341464@gmail.com> * Update according to PR suggestions * Reword sentences of deployment article for clarification & remove mention of portability * Fix typos/grammar errors within TextChannelProperties * Add the logo SVG to the page navbar * Implement changing logo image based on theme color using CSS background image * Add a favicon * use the purple logomark instead of white * hack? set the title to navbar svg to read "Discord.Net Docs"
This commit is contained in:
@@ -31,17 +31,15 @@ be a violation of the SRP (Single Responsibility Principle).
|
||||
Another major issue is if your command is marked with
|
||||
`RunMode.Async`, [ExecuteAsync] will **always** return a successful
|
||||
[ExecuteResult] instead of the actual result. You can learn more
|
||||
about the impact in the [FAQ](xref:FAQ.Commands.General).
|
||||
about the impact in @FAQ.Commands.General.
|
||||
|
||||
## CommandExecuted Event
|
||||
|
||||
Enter [CommandExecuted], an event that was introduced in
|
||||
Discord.Net 2.0. This event is raised whenever a command is
|
||||
successfully executed **without any run-time exceptions** or **any
|
||||
parsing or precondition failure**. This means this event can be
|
||||
used to streamline your post-execution design, and the best thing
|
||||
about this event is that it is not prone to `RunMode.Async`'s
|
||||
[ExecuteAsync] drawbacks.
|
||||
executed regardless of its execution status. This means this
|
||||
event can be used to streamline your post-execution design,
|
||||
is not prone to `RunMode.Async`'s [ExecuteAsync] drawbacks.
|
||||
|
||||
Thus, we can begin working on code such as:
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class CommandHandler
|
||||
|
||||
// Keep in mind that result does not indicate a return value
|
||||
// rather an object stating if the command executed successfully.
|
||||
var result = await _command.ExecuteAsync(
|
||||
var result = await _commands.ExecuteAsync(
|
||||
context: context,
|
||||
argPos: argPos,
|
||||
services: null);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext context, IResult result)
|
||||
public async Task OnCommandExecutedAsync(Optional<CommandInfo> command, ICommandContext context, IResult result)
|
||||
{
|
||||
switch(result)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ public async Task SetupAsync()
|
||||
// Hook the command handler
|
||||
_client.MessageReceived += HandleCommandAsync;
|
||||
}
|
||||
public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext context, IResult result)
|
||||
public async Task OnCommandExecutedAsync(Optional<CommandInfo> command, ICommandContext context, IResult result)
|
||||
{
|
||||
// We have access to the information of the command executed,
|
||||
// the context of the command, and the result returned from the
|
||||
@@ -20,19 +20,19 @@ public async Task OnCommandExecutedAsync(CommandInfo command, ICommandContext co
|
||||
|
||||
// ...or even log the result (the method used should fit into
|
||||
// your existing log handler)
|
||||
await _log.LogAsync(new LogMessage(LogSeverity.Info, "CommandExecution", $"{command?.Name} was executed at {DateTime.UtcNow}."));
|
||||
var commandName = command.IsSpecified ? command.Value.Name : "A command";
|
||||
await _log.LogAsync(new LogMessage(LogSeverity.Info,
|
||||
"CommandExecution",
|
||||
$"{commandName} was executed at {DateTime.UtcNow}."));
|
||||
}
|
||||
public async Task HandleCommandAsync(SocketMessage msg)
|
||||
{
|
||||
var message = messageParam as SocketUserMessage;
|
||||
if (message == null) return;
|
||||
int argPos = 0;
|
||||
if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(_client.CurrentUser, ref argPos)) || message.Author.IsBot) return;
|
||||
if (!(message.HasCharPrefix('!', ref argPos) ||
|
||||
message.HasMentionPrefix(_client.CurrentUser, ref argPos)) ||
|
||||
message.Author.IsBot) return;
|
||||
var context = new SocketCommandContext(_client, message);
|
||||
var result = await _commands.ExecuteAsync(context, argPos, _services);
|
||||
// Optionally, you may pass the result manually into your
|
||||
// CommandExecuted event handler if you wish to handle parsing or
|
||||
// precondition failures in the same method.
|
||||
|
||||
// await OnCommandExecutedAsync(null, context, result);
|
||||
await _commands.ExecuteAsync(context, argPos, _services);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// Bad code!!!
|
||||
var result = await _commands.ExecuteAsync(context, argPos, _services);
|
||||
if (result.CommandError != null)
|
||||
switch(result.CommandError)
|
||||
{
|
||||
case CommandError.BadArgCount:
|
||||
await context.Channel.SendMessageAsync("Parameter count does not match any command's.");
|
||||
await context.Channel.SendMessageAsync(
|
||||
"Parameter count does not match any command's.");
|
||||
break;
|
||||
default:
|
||||
await context.Channel.SendMessageAsync($"An error has occurred {result.ErrorReason}");
|
||||
await context.Channel.SendMessageAsync(
|
||||
$"An error has occurred {result.ErrorReason}");
|
||||
break;
|
||||
}
|
||||
Reference in New Issue
Block a user