Browse Source

Improve readability

pull/988/head
Hsu Still 7 years ago
parent
commit
6c7a8c8819
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
2 changed files with 11 additions and 9 deletions
  1. +8
    -4
      docs/guides/concepts/entities.md
  2. +3
    -5
      docs/guides/concepts/samples/entities.cs

+ 8
- 4
docs/guides/concepts/entities.md View File

@@ -31,6 +31,9 @@ But that doesn't mean a message _can't_ come from a
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
@@ -47,13 +50,14 @@ DiscordSocketClient.

> [!TIP]
> It is **vital** that you use the proper IDs for an entity when using
> a GetXXX method. It is recommended that you enable Discord's
> a `GetXXX` method. It is recommended that you enable Discord's
> _developer mode_ to allow easy access to entity IDs, found in
> Settings > Appearance > Advanced.
> Settings > Appearance > Advanced. Read more about it in the
> [FAQ](xref:FAQ.Basics.GetStarted) 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
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.



+ 3
- 5
docs/guides/concepts/samples/entities.cs View File

@@ -1,13 +1,11 @@
public string GetChannelTopic(ulong id)
{
var channel = client.GetChannel(81384956881809408) as SocketTextChannel;
if (channel == null) return "";
return channel.Topic;
return channel?.Topic;
}

public string GuildOwner(SocketChannel channel)
public SocketGuildUser GetGuildOwner(SocketChannel channel)
{
var guild = (channel as SocketGuildChannel)?.Guild;
if (guild == null) return "";
return Context.Guild.Owner.Username;
return guild?.Owner;
}

Loading…
Cancel
Save