@@ -10,7 +10,7 @@ Casting only works for types that inherit the base type that you want to unbox f | |||||
`IUser` cannot be cast to `IMessage`. | `IUser` cannot be cast to `IMessage`. | ||||
> [!NOTE] | > [!NOTE] | ||||
> Interfaces **can** be cast to other interfaces, as long as they inherit eachother. | |||||
> Interfaces **can** be cast to other interfaces, as long as they inherit each other. | |||||
> The same goes for reverse casting. As long as some entity can be simplified into what it inherits, your cast will pass. | > The same goes for reverse casting. As long as some entity can be simplified into what it inherits, your cast will pass. | ||||
## Boxing | ## Boxing | ||||
@@ -35,7 +35,7 @@ it will become said type, and its properties can be accessed. | |||||
[!code-csharp[Casting](samples/casting.cs)] | [!code-csharp[Casting](samples/casting.cs)] | ||||
> [!WARNING] | > [!WARNING] | ||||
> If the type you're casting to is null, a `NullReferenceException` will be thrown when its called. | |||||
> If the type you're casting to is null, a `NullReferenceException` will be thrown when it's called. | |||||
> This makes safety casting much more interesting to use, as it prevents this exception from being thrown. | > This makes safety casting much more interesting to use, as it prevents this exception from being thrown. | ||||
## Safety casting | ## Safety casting | ||||
@@ -54,8 +54,8 @@ exist under a category. | |||||
 |  | ||||
* A **Rest Followup Message** ([RestFollowupMessage]) is a message returned by followup on on an interaction. | * A **Rest Followup Message** ([RestFollowupMessage]) is a message returned by followup on on an interaction. | ||||
* A **Rest Interaction Message** ([RestInteractionMessage]) is a message returned by the interactions' original response. | |||||
* A **Rest User Message** ([RestUserMessage]) is a message sent over rest, can be any of the above. | |||||
* A **Rest Interaction Message** ([RestInteractionMessage]) is a message returned by the interaction's original response. | |||||
* A **Rest User Message** ([RestUserMessage]) is a message sent over rest; it can be any of the above. | |||||
* An **User Message** ([IUserMessage]) is a message sent by a user. | * An **User Message** ([IUserMessage]) is a message sent by a user. | ||||
* A **System Message** ([ISystemMessage]) is a message sent by Discord itself. | * A **System Message** ([ISystemMessage]) is a message sent by Discord itself. | ||||
* A **Message** ([IMessage]) can be any of the above. | * A **Message** ([IMessage]) can be any of the above. | ||||
@@ -1,4 +1,4 @@ | |||||
// Say we have an entity, for the simplicity of this example, it will appear from thin air. | |||||
// Say we have an entity; for the simplicity of this example, it will appear from thin air. | |||||
IChannel channel; | IChannel channel; | ||||
// If we want this to be an ITextChannel so we can access the properties of a text channel inside of a guild, an approach would be: | // If we want this to be an ITextChannel so we can access the properties of a text channel inside of a guild, an approach would be: | ||||
@@ -1,4 +1,4 @@ | |||||
// RestUser entities expose the accentcolor and banner of a user. | |||||
// RestUser entities expose the accent color and banner of a user. | |||||
// This being one of the few use-cases for requesting a RestUser instead of depending on the Socket counterpart. | // This being one of the few use-cases for requesting a RestUser instead of depending on the Socket counterpart. | ||||
public static EmbedBuilder WithUserColor(this EmbedBuilder builder, IUser user) | public static EmbedBuilder WithUserColor(this EmbedBuilder builder, IUser user) | ||||
{ | { | ||||
@@ -4,7 +4,7 @@ private void MyFunction(IMessage message) | |||||
if (message is not IUserMessage userMessage) | if (message is not IUserMessage userMessage) | ||||
return; | return; | ||||
// Because we do the above check inline (dont give the statement a body), | |||||
// Because we do the above check inline (don't give the statement a body), | |||||
// the code will still declare `userMessage` as available outside of the above statement. | // the code will still declare `userMessage` as available outside of the above statement. | ||||
Console.WriteLine(userMessage.Author); | Console.WriteLine(userMessage.Author); | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
IUser user; | IUser user; | ||||
// Here we can pre-define the actual declaration of said IGuildUser object, | // Here we can pre-define the actual declaration of said IGuildUser object, | ||||
// so we dont need to cast additionally inside of the statement. | |||||
// so we don't need to cast additionally inside of the statement. | |||||
if (user is IGuildUser guildUser) | if (user is IGuildUser guildUser) | ||||
{ | { | ||||
Console.WriteLine(guildUser.JoinedAt); | Console.WriteLine(guildUser.JoinedAt); | ||||
@@ -6,7 +6,7 @@ using Discord.WebSocket; | |||||
namespace BasicBot | namespace BasicBot | ||||
{ | { | ||||
// This is a minimal, bare-bones example of using Discord.Net | |||||
// This is a minimal, bare-bones example of using Discord.Net. | |||||
// | // | ||||
// If writing a bot with commands/interactions, we recommend using the Discord.Net.Commands/Discord.Net.Interactions | // If writing a bot with commands/interactions, we recommend using the Discord.Net.Commands/Discord.Net.Interactions | ||||
// framework, rather than handling them yourself, like we do in this sample. | // framework, rather than handling them yourself, like we do in this sample. | ||||