Docs/components v2 :wires: (#3162)
* new pages :3 * fimished intro page * fimished interaction page * remove unused shit * I think we are done lmao * I lied, fixed some small mistakes * Update docs/guides/components_v2/interaction.md Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> * misha quality assurance :3 + breakings pages * Apply suggestions from code review Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> * component types guide expanded * :3 * Apply suggestions from code review Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com> --------- Co-authored-by: Mihail Gribkov <61027276+Misha-133@users.noreply.github.com>
This commit is contained in:
91
docs/guides/breakings/v2_to_v3_guide.md
Normal file
91
docs/guides/breakings/v2_to_v3_guide.md
Normal file
@@ -0,0 +1,91 @@
|
||||
---
|
||||
uid: Guides.Breakings.V2V3Guide
|
||||
title: V2 -> V3 Guide
|
||||
---
|
||||
|
||||
# V2 to V3 Guide
|
||||
|
||||
V3 is designed to be a more feature complete, more reliable,
|
||||
and more flexible library than any previous version.
|
||||
|
||||
Below are the most notable breaking changes that you would need to update your code to work with V3.
|
||||
|
||||
### GatewayIntents
|
||||
|
||||
As Discord.NET has upgraded from Discord API v6 to API v9,
|
||||
`GatewayIntents` must now be specified in the socket config, as well as on the [developer portal].
|
||||
|
||||
```cs
|
||||
|
||||
// Where ever you declared your websocket client.
|
||||
DiscordSocketClient _client;
|
||||
|
||||
...
|
||||
|
||||
var config = new DiscordSocketConfig()
|
||||
{
|
||||
.. // Other config options can be presented here.
|
||||
GatewayIntents = GatewayIntents.All
|
||||
}
|
||||
|
||||
_client = new DiscordSocketClient(config);
|
||||
|
||||
```
|
||||
|
||||
#### Common intents:
|
||||
|
||||
- AllUnprivileged: This is a group of most common intents, that do NOT require any [developer portal] intents to be enabled.
|
||||
This includes intents that receive messages such as: `GatewayIntents.GuildMessages, GatewayIntents.DirectMessages`
|
||||
- GuildMembers: An intent disabled by default, as you need to enable it in the [developer portal].
|
||||
- MessageContent: An intent also disabled by default as you also need to enable it in the [developer portal].
|
||||
- GuildPresences: Also disabled by default, this intent together with `GuildMembers` are the only intents not included in `AllUnprivileged`.
|
||||
- All: All intents, it is ill advised to use this without care, as it _can_ cause a memory leak from presence.
|
||||
The library will give responsive warnings if you specify unnecessary intents.
|
||||
|
||||
> [!NOTE]
|
||||
> All gateway intents, their Discord API counterpart and their enum value are listed
|
||||
> [HERE](xref:Discord.GatewayIntents)
|
||||
|
||||
#### Stacking intents:
|
||||
|
||||
It is common that you require several intents together.
|
||||
The example below shows how this can be done.
|
||||
|
||||
```cs
|
||||
|
||||
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildMembers | ..
|
||||
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Further documentation on the ` | ` operator can be found
|
||||
> [HERE](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators)
|
||||
|
||||
[developer portal]: https://discord.com/developers/
|
||||
|
||||
### UserLeft event
|
||||
|
||||
UserLeft has been changed to have the `SocketUser` and `SocketGuild` parameters instead of a `SocketGuildUser` parameter.
|
||||
Because of this, guild-only user data cannot be retrieved from this user anymore, as this user is not part of the guild.
|
||||
|
||||
### ReactionAdded event
|
||||
|
||||
The reaction added event has been changed to have both parameters cacheable.
|
||||
This allows you to download the channel and message if they aren't cached instead of them being null.
|
||||
|
||||
### UserIsTyping Event
|
||||
|
||||
The user is typing event has been changed to have both parameters cacheable.
|
||||
This allows you to download the user and channel if they aren't cached instead of them being null.
|
||||
|
||||
### Presence
|
||||
|
||||
There is a new event called `PresenceUpdated` that is called when a user's presence changes,
|
||||
instead of `GuildMemberUpdated` or `UserUpdated`.
|
||||
If your code relied on these events to get presence data then you need to update it to work with the new event.
|
||||
|
||||
## Migrating your commands to application commands
|
||||
|
||||
The new interaction service was designed to act like the previous service for text-based commands.
|
||||
Your pre-existing code will continue to work, but you will need to migrate your modules and response functions to use the new
|
||||
interaction service methods. Documentation on this can be found in the [Guides](xref:Guides.IntFw.Intro).
|
||||
40
docs/guides/breakings/v3.18.md
Normal file
40
docs/guides/breakings/v3.18.md
Normal file
@@ -0,0 +1,40 @@
|
||||
---
|
||||
uid: Guides.Breakings.V3_18
|
||||
title: V3.18
|
||||
---
|
||||
|
||||
# V3.18
|
||||
|
||||
Among the changes in V3.18 was components V2, while splendid, it did bring with it a few changes you should be aware of.
|
||||
|
||||
- IMessage
|
||||
|
||||
Messages components type has changed. As a patch you can convert it to an `IEnumerable<ActionRowComponent>` again like so:
|
||||
```cs
|
||||
IMessage message = component.Message;
|
||||
IReadOnlyCollection<IMessageComponent>? components = message.Components;
|
||||
IEnumerable<ActionRowComponent>? componentsLegacy = components.OfType<ActionRowComponent>();
|
||||
```
|
||||
|
||||
- Nested components
|
||||
|
||||
The usage of components with `ActionRowBuilder` and `ComponentBuilder` has a type change as well. You can find examples in [Components_V2_Advanced].
|
||||
|
||||
- Components V2 Flag
|
||||
|
||||
To use Components V2 in a message (through `ModifyAsync`/`UpdateAsync`/...), a specific flag has to be set. This cannot be undone though :^). You only have to set it if you modify a message that didn't have components v2 in them to begin with (or if you already set the flag manually - obviously). This means that if you created a message with your bot that has components in it, the flag will automatically be set.
|
||||
|
||||
Otherwise, you can manually set it like so:
|
||||
|
||||
```cs
|
||||
MessageFlags? flags = component.Message.Flags ?? MessageFlags.None;
|
||||
flags = flags | MessageFlags.ComponentsV2;
|
||||
|
||||
await component.UpdateAsync(m =>
|
||||
{
|
||||
m.Flags = flags;
|
||||
m.Components = cv2builder.Build();
|
||||
});
|
||||
```
|
||||
|
||||
[Components_V2_Advanced]: xref:Guides.ComponentsV2.Advanced
|
||||
Reference in New Issue
Block a user