Browse Source

Added more enforcement checks on builder. Closes #3

pull/1923/head
quin lynch 4 years ago
parent
commit
b8ba5b94c8
1 changed files with 8 additions and 0 deletions
  1. +8
    -0
      src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs

+ 8
- 0
src/Discord.Net.Core/Entities/Interactions/Message Components/ComponentBuilder.cs View File

@@ -247,9 +247,17 @@ namespace Discord

public ButtonComponent Build()
{
if (string.IsNullOrEmpty(this.Label) && this.Emote == null)
throw new ArgumentException("A button must have an Emote or a label!");

if (!string.IsNullOrEmpty(this.Url) && !string.IsNullOrEmpty(this.CustomId))
throw new InvalidOperationException("A button cannot contain a URL and a CustomId");

if (this.Style == ButtonStyle.Link && !string.IsNullOrEmpty(this.CustomId))
this.CustomId = null;
else if (!string.IsNullOrEmpty(this.Url))
this.Url = null;

return new ButtonComponent(this.Style, this.Label, this.Emote, this.CustomId, this.Url, this.Disabled);
}
}


Loading…
Cancel
Save