Skip to content

Commit

Permalink
[Fix] ButtonBuilder validations(#2943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Misha-133 authored Jun 17, 2024
1 parent 9d92435 commit 5a71ad3
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,6 @@ public ButtonBuilder WithSkuId(ulong? skuId)
/// <exception cref="InvalidOperationException">A non-link button must contain a custom id</exception>
public ButtonComponent Build()
{
if (string.IsNullOrWhiteSpace(Label) && Emote is null)
throw new InvalidOperationException("A button must have an Emote or a label!");

var a = 0;
if (!string.IsNullOrWhiteSpace(Url))
a++;
Expand All @@ -293,6 +290,8 @@ public ButtonComponent Build()
case ButtonStyle.Success:
case ButtonStyle.Danger:
{
if (string.IsNullOrWhiteSpace(Label) && Emote is null)
throw new InvalidOperationException("A button must have an Emote or a label!");
if (string.IsNullOrWhiteSpace(CustomId))
throw new InvalidOperationException("Non-link and non-premium buttons must have a custom id associated with them");

Expand All @@ -301,6 +300,8 @@ public ButtonComponent Build()

case ButtonStyle.Link:
{
if (string.IsNullOrWhiteSpace(Label) && Emote is null)
throw new InvalidOperationException("A button must have an Emote or a label!");
if (string.IsNullOrWhiteSpace(Url))
throw new InvalidOperationException("Link buttons must have a link associated with them");
UrlValidation.ValidateButton(Url);
Expand Down

0 comments on commit 5a71ad3

Please sign in to comment.