Adding Entity guides, flowcharts, better sample system. (#2054)
* initial * Interaction glossary entry * Sharded Interaction sample * Renames into solution * Debugging samples * Modify target location for webhookclient * Finalizing docs work, resolving docfx errors. * Adding threaduser to user chart * Add branch info to readme. * Edits to user chart * Resolve format for glossary entries * Patch sln target * Issue with file naming fixed * Patch 1/x for builds * Appending suggestions
This commit is contained in:
7
docs/guides/entities/samples/casting.cs
Normal file
7
docs/guides/entities/samples/casting.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
// Say we have an entity; for the simplicity of this example, it will appear from thin air.
|
||||
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:
|
||||
ITextChannel textChannel = channel as ITextChannel;
|
||||
|
||||
await textChannel.DoSomethingICantWithIChannelAsync();
|
||||
8
docs/guides/entities/samples/restentities.cs
Normal file
8
docs/guides/entities/samples/restentities.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
// 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.
|
||||
public static EmbedBuilder WithUserColor(this EmbedBuilder builder, IUser user)
|
||||
{
|
||||
var restUser = await _client.Rest.GetUserAsync(user.Id);
|
||||
return builder.WithColor(restUser.AccentColor ?? Color.Blue);
|
||||
// The accent color can still be null, so a check for this needs to be done to prevent an exception to be thrown.
|
||||
}
|
||||
10
docs/guides/entities/samples/safety-cast-pass.cs
Normal file
10
docs/guides/entities/samples/safety-cast-pass.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
private void MyFunction(IMessage message)
|
||||
{
|
||||
// Here we do the reverse as in the previous examples, and let it continue the code below if it IS an IUserMessage
|
||||
if (message is not IUserMessage userMessage)
|
||||
return;
|
||||
|
||||
// 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.
|
||||
Console.WriteLine(userMessage.Author);
|
||||
}
|
||||
9
docs/guides/entities/samples/safety-cast-var.cs
Normal file
9
docs/guides/entities/samples/safety-cast-var.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
IUser user;
|
||||
|
||||
// Here we can pre-define the actual declaration of said IGuildUser object,
|
||||
// so we don't need to cast additionally inside of the statement.
|
||||
if (user is IGuildUser guildUser)
|
||||
{
|
||||
Console.WriteLine(guildUser.JoinedAt);
|
||||
}
|
||||
// Check failed.
|
||||
8
docs/guides/entities/samples/safety-cast.cs
Normal file
8
docs/guides/entities/samples/safety-cast.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
IUser user;
|
||||
|
||||
// Here we check if the user is an IGuildUser, if not, let it pass. This ensures its not null.
|
||||
if (user is IGuildUser)
|
||||
{
|
||||
Console.WriteLine("This user is in a guild!");
|
||||
}
|
||||
// Check failed.
|
||||
11
docs/guides/entities/samples/socketentities.cs
Normal file
11
docs/guides/entities/samples/socketentities.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
public string GetChannelTopic(ulong id)
|
||||
{
|
||||
var channel = client.GetChannel(81384956881809408) as SocketTextChannel;
|
||||
return channel?.Topic;
|
||||
}
|
||||
|
||||
public SocketGuildUser GetGuildOwner(SocketChannel channel)
|
||||
{
|
||||
var guild = (channel as SocketGuildChannel)?.Guild;
|
||||
return guild?.Owner;
|
||||
}
|
||||
9
docs/guides/entities/samples/unboxing.cs
Normal file
9
docs/guides/entities/samples/unboxing.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
IUser user;
|
||||
|
||||
// Here we use inline unboxing to make a call to its member (if available) only once.
|
||||
|
||||
// Note that if the entity we're trying to cast to is null, this will throw a NullReferenceException.
|
||||
Console.WriteLine(((IGuildUser)user).Nickname);
|
||||
|
||||
// In case you are certain the entity IS said member, you can also use unboxing to declare variables.
|
||||
IGuildUser guildUser = (IGuildUser)user;
|
||||
Reference in New Issue
Block a user