Skip to content

Commit f75bb54

Browse files
authored
Merge pull request #742 from Aiko-IT-Systems/copilot/move-custom-id-to-button-component
Fix CustomId incorrectly set on link and premium buttons
2 parents 12b96c0 + ff18f6e commit f75bb54

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

DisCatSharp/Entities/Components/Buttons/DiscordButtonComponent.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public DiscordButtonComponent(ButtonStyle style, string customId = null, string
7474
}
7575
}
7676

77+
/// <summary>
78+
/// The custom Id of this button. This is sent back when a user presses it.
79+
/// Applies to buttons with Primary, Secondary, Success, and Danger styles.
80+
/// Link buttons use URLs and Premium buttons use SKU IDs instead of custom IDs.
81+
/// </summary>
82+
[JsonProperty("custom_id", NullValueHandling = NullValueHandling.Ignore)]
83+
public override string? CustomId { get; internal set; } = Guid.NewGuid().ToString();
84+
7785
/// <summary>
7886
/// The style of the button.
7987
/// </summary>

DisCatSharp/Entities/Components/DiscordComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ internal DiscordComponent()
2626
public ComponentType Type { get; internal set; }
2727

2828
/// <summary>
29-
/// The custom Id of this component, if applicable. Not applicable on ActionRow(s) and link buttons.
29+
/// The custom Id of this component, if applicable. Not applicable on ActionRow(s), link buttons, and premium buttons.
3030
/// </summary>
3131
[JsonProperty("custom_id", NullValueHandling = NullValueHandling.Ignore)]
32-
public string? CustomId { get; internal set; } = Guid.NewGuid().ToString();
32+
public virtual string? CustomId { get; internal set; }
3333

3434
/// <summary>
3535
/// Gets the Id of the compenent. Auto populated by discord if not provided.

DisCatSharp/Entities/Components/DiscordFileUploadComponent.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public DiscordFileUploadComponent(string customId = null, int minOptions = 1, in
3535
this.Required = required;
3636
}
3737

38+
/// <summary>
39+
/// The custom Id of this file upload component. This is sent back when files are uploaded.
40+
/// </summary>
41+
[JsonProperty("custom_id", NullValueHandling = NullValueHandling.Ignore)]
42+
public override string? CustomId { get; internal set; } = Guid.NewGuid().ToString();
43+
3844
/// <summary>
3945
/// Whether this file upload component is required. For modals.
4046
/// </summary>

DisCatSharp/Entities/Components/Selects/DiscordBaseSelectComponent.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ internal DiscordBaseSelectComponent(ComponentType type, string placeholder, stri
6060
internal DiscordBaseSelectComponent()
6161
{ }
6262

63+
/// <summary>
64+
/// The custom Id of this select component. This is sent back when a user interacts with the select menu.
65+
/// </summary>
66+
[JsonProperty("custom_id", NullValueHandling = NullValueHandling.Ignore)]
67+
public override string? CustomId { get; internal set; } = Guid.NewGuid().ToString();
68+
6369
/// <summary>
6470
/// The text to show when no option is selected.
6571
/// </summary>

DisCatSharp/Entities/Components/Text/DiscordTextInputComponent.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ public DiscordTextInputComponent(TextComponentStyle style, string? customId = nu
112112
this.Value = defaultValue;
113113
}
114114

115+
/// <summary>
116+
/// The custom Id of this text input component. This is sent back when the form is submitted.
117+
/// </summary>
118+
[JsonProperty("custom_id", NullValueHandling = NullValueHandling.Ignore)]
119+
public override string? CustomId { get; internal set; } = Guid.NewGuid().ToString();
120+
115121
/// <summary>
116122
/// The style of the text input component.
117123
/// </summary>

0 commit comments

Comments
 (0)