Guilds

Guilds vs. servers

I often see people confusing guilds with servers, so i thought i'd clear things up real quick.

A "guild" is the technical term for what's known as a "server" in the UI. What i call "servers" throughout the docs are actual servers that u can connect to, such as the media servers used to speak and livestream in voice channels.

Different guild objects

Discord will often only provide parts of a guild object. Anarchy therefore has various guild classes that vary in information to fit what's given to us. Here's a list of all the different classes:

  • MinimalGuild: The class with the least possible information. The only property is .Id, but that's enough to call most of the endpoints.

  • PartialGuild: Returned only by the .GetGuilds() method. Only unique feature of this class is that all your permissions are present.

  • DiscordGuild: Closest to you'll get to a full guild through the REST API.

  • UnavailableGuild: Only used in the OnLeftGuild event. The .Removed member can be used to check whether the user was actually removed, or if the server is having an outage.

  • SocketGuild: These are only provided through the gateway. These are provided to you through events, as well as .GetCachedGuilds() and .GetCachedGuild() if you have caching enabled (duh).

Permissions

Permissions are a crucial part of Discord guilds. They're what decides what a member can and cannot do. Behind the scenes, permissions are a number comprised of multiple values OR'd. The DiscordPermission maps the values, so just doing the bitwise operations yourself works, although there are some extension methods available to make your life easier.

Manual bitwise operations

DiscordPermission perms = DiscordPermission.None; // create empty set
perms |= DiscordPermission.KickMembers; // add a permission
perms &= ~DiscordPermission.KickMembers; // remove the permission
perms.HasFlag(DiscordPermission.KickMembers); // returns false

Using the helper methods

DiscordPermission perms = DiscordPermission.None
                          .Add(DiscordPermission.KickMembers)
                          .Remove(DiscordPermission.KickMembers);

perms.Has(DiscordPermission.KickMembers); // returns false

Multiple permissions can, in multiple examples, be checked for / added / removed in a single call.

Permission overwrites

Discord allows overwriting of members/roles in the scope of a singular (or more because of synchronized permissions) channel. A GuildChannel's permission overwrites are located at .PermissionOverwrites.

GuildMember.GetPermissions() has an overload accepting an IEnumerable<DiscordPermissionOverwrite>. Example:

member.GetPermissions().Has(DiscordPermission.SendMessages); // returns true
member.GetPermissions(channel.PermissionOverwrites)... // returns false

In this example, the user is allowed to send messages according to the roles, but an overwrite, well... overwrites that.

Members

Discord have recently removed the ability for user accounts to request members the same way bot accounts do. Anarchy has methods for both, so make sure to use the right one!

Bots can use the .GetGuildMembers() method, whilst users can only use .GetGuildChannelMembers(). The method for users works like Discord's Member List, meaning that it only gets members that have access to it. Both methods return an IReadOnlyList<GuildMember> and are available for gateway clients only.

Webhooks

There are 2 types of webhooks: incoming webhooks, which send messages and are authenticated using a token, and channel followers that crosspost messages from news channels. Anarchy has extensive functionality for both of them.

Requesting a webhook

ulong hookId = 42069999;
string token = "jUEugVMozmyy4lnU1tlPXKVFjWnSYZeAmABcttxy5KW5vYJyA_YDCmjtR2WJuKaul2RV";

// Gets a webhook by it's ID and token.
// If you have the ManageWebhooks permission on it's parent guild, you don't have to specify the token.
DiscordWebhook hook = client.GetWebhook(hookId, token);
Console.WriteLine(hook.Name);

// You can also do this if you don't want to create a client and have it's token.
// This constructor only exists in DiscordDefaultWebhook because channel followers don't have tokens.
DiscordDefaultWebhook hook = new DiscordDefaultWebhook(hookId, token);

Incoming webhooks

Incoming webhooks are the classic webhooks we all know and love. They simply send messages as you command.

Sending messages

DiscordDefaultWebhook hook = (DiscordDefaultWebhook)client.GetWebhook(42069999);

// All parameters except the first are optional
hook.SendMessage("test", null, new DiscordWebhookProfile()
{
    Username = "joe mama",
    AvatarUrl = "https://anarchyteam.dev/favicon.ico"
});

Channel followers

Channel followers, or crossposters, are webhooks that send messages from a news channel to the specified channel, hence the term "crossposting".

In the following examples, the 'sourceChannel' will be a TextChannel with a .Type of News.

Creating crossposters

sourceChannel.Follow(42069425); // pass the ID of your own channel here

Crossposting/publishing messages

If you have permissions to manage the news channel, you can "publish" messages, which will forward them to all the channel followers for the channel.

foreach (DiscordMessage message in sourceChannel.GetMessages(new MessageFilters() { Limit = 50 }))
    message.Crosspost();

Last updated