* Remove template in favor of official samples * Fixed a variable name copy pasta mistake line 35 was _database.GetData() instead of DBService.GetData() * Experimental theme change * Change paragraph, code, heading fonts * Widen viewport * Update DocFX.Plugins.LastModified v1.2.3 * Exclude Discord.API in docs * Add remarks for SocketReaction properties * Add examples for BaseSocketClient.Events * Add additional clarification for some methods * Move IUser and IGuildChannel examples * Clarify several guides samples with notes - Reword TypeReader comment to avoid giving the idea that the sample itself is "obsolete" - Remove CommandException logging comment regarding C#7.0 as the version is now the standard across VS2017 and up - Remove suggestion about handling result in command handler since it is now advised to use CommandExecuted instead + Add additional comment to clarify ctor for DI setup * Add/migrate code examples * Incorporate material design theme License @ https://github.com/ovasquez * Update installation and nightly guide * Fix improper indentations made obvious by the widen viewport * Fix minor grammar issues + Add installation for nightly build using dotnet CLI * Fix nav level indentation * Revise "Your First Bot" article * Merge some paragraphs to avoid clutter while keeping readability * Reword the use of command framework + Add additional warning/note about environment variable * Add additional indent level * Fix indentation text warping * Remove connections sample * Update logging sample Remove redundant part of the sample * Remove mention of RPC * Remove misleading section about commands - Remove command sample from complete snippet * Revise "Your First Bot" command paragraphs * Change wording to hint devs that additional command parser packages may be available, as more and more begin to crop up * Update themes * Add XML docs contribution guidelines Update guidelines * Update CommandExecuted remarks * Fix precondition remarks typo no one saw that ok * Fix permission sample in docfx * Fix IMessageChannel samples * Update docs/_template/light-dark-theme/styles/docfx.vendor.minify.css Co-Authored-By: Still34 <341464@gmail.com> * Update docs/_template/light-dark-theme/styles/material.css Co-Authored-By: Still34 <341464@gmail.com> * Update docs/_template/light-dark-theme/styles/material.css Co-Authored-By: Still34 <341464@gmail.com>
2.3 KiB
uid, title
| uid | title |
|---|---|
| Guides.Concepts.Entities | Entities |
Entities in Discord.Net
Note
This article is written with the Socket variants of entities in mind, not the general interfaces or Rest entities.
Discord.Net provides a versatile entity system for navigating the Discord API.
Inheritance
Due to the nature of the Discord API, some entities are designed with
multiple variants; for example, SocketUser and SocketGuildUser.
All models will contain the most detailed version of an entity possible, even if the type is less detailed.
For example, in the case of the MessageReceived event, a
SocketMessage is passed in with a channel property of type
SocketMessageChannel. All messages come from channels capable of
messaging, so this is the only variant of a channel that can cover
every single case.
But that doesn't mean a message can't come from a
SocketTextChannel, which is a message channel in a guild. To
retrieve information about a guild from a message entity, you will
need to cast its channel object to a SocketTextChannel.
You can find out various types of entities in the @FAQ.Misc.Glossary page.
Navigation
All socket entities have navigation properties on them, which allow you to easily navigate to an entity's parent or children. As explained above, you will sometimes need to cast to a more detailed version of an entity to navigate to its parent.
Accessing Entities
The most basic forms of entities, SocketGuild, SocketUser, and
SocketChannel can be pulled from the DiscordSocketClient's global
cache, and can be retrieved using the respective GetXXX method on
DiscordSocketClient.
Tip
It is vital that you use the proper IDs for an entity when using a
GetXXXmethod. It is recommended that you enable Discord's developer mode to allow easy access to entity IDs, found in Settings > Appearance > Advanced. Read more about it in the FAQ page.
More detailed versions of entities can be pulled from the basic
entities, e.g., SocketGuild.GetUser, which returns a
SocketGuildUser, or SocketGuild.GetChannel, which returns a
SocketGuildChannel. Again, you may need to cast these objects to get
a variant of the type that you need.
Sample
[!code-csharpEntity Sample]