Expose the 'fields' collection on EmbedBuilder (#603)
* remove tip in docs about SocketEntity.Discord * Expose the 'Fields' collection on EmbedBuilder After some discussion I decided that there was really no reason to keep this private, and it didn't really go along with the rest of the design of the EmbedBuilder. This is NOT a breaking change. Exposing this property should not have any negative effects. * Don't allow EmbedBuilder's Fields to be set to null
This commit is contained in:
committed by
RogueException
parent
576a52cdc6
commit
d189bb9748
@@ -35,9 +35,6 @@ you to easily navigate to an entity's parent or children. As explained
|
|||||||
above, you will sometimes need to cast to a more detailed version of
|
above, you will sometimes need to cast to a more detailed version of
|
||||||
an entity to navigate to its parent.
|
an entity to navigate to its parent.
|
||||||
|
|
||||||
All socket entities have a `Discord` property, which will allow you
|
|
||||||
to access the parent `DiscordSocketClient`.
|
|
||||||
|
|
||||||
### Accessing Entities
|
### Accessing Entities
|
||||||
|
|
||||||
The most basic forms of entities, `SocketGuild`, `SocketUser`, and
|
The most basic forms of entities, `SocketGuild`, `SocketUser`, and
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ namespace Discord
|
|||||||
public class EmbedBuilder
|
public class EmbedBuilder
|
||||||
{
|
{
|
||||||
private readonly Embed _embed;
|
private readonly Embed _embed;
|
||||||
private readonly List<EmbedFieldBuilder> _fields;
|
|
||||||
|
|
||||||
public EmbedBuilder()
|
public EmbedBuilder()
|
||||||
{
|
{
|
||||||
_embed = new Embed("rich");
|
_embed = new Embed("rich");
|
||||||
_fields = new List<EmbedFieldBuilder>();
|
Fields = new List<EmbedFieldBuilder>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title { get { return _embed.Title; } set { _embed.Title = value; } }
|
public string Title { get { return _embed.Title; } set { _embed.Title = value; } }
|
||||||
@@ -25,6 +24,16 @@ namespace Discord
|
|||||||
|
|
||||||
public EmbedAuthorBuilder Author { get; set; }
|
public EmbedAuthorBuilder Author { get; set; }
|
||||||
public EmbedFooterBuilder Footer { get; set; }
|
public EmbedFooterBuilder Footer { get; set; }
|
||||||
|
private List<EmbedFieldBuilder> _fields;
|
||||||
|
public List<EmbedFieldBuilder> Fields
|
||||||
|
{
|
||||||
|
get => _fields;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != null) _fields = value;
|
||||||
|
else throw new ArgumentNullException("Cannot set an embed builder's fields collection to null", nameof(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public EmbedBuilder WithTitle(string title)
|
public EmbedBuilder WithTitle(string title)
|
||||||
{
|
{
|
||||||
@@ -98,7 +107,7 @@ namespace Discord
|
|||||||
.WithIsInline(false)
|
.WithIsInline(false)
|
||||||
.WithName(name)
|
.WithName(name)
|
||||||
.WithValue(value);
|
.WithValue(value);
|
||||||
_fields.Add(field);
|
Fields.Add(field);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public EmbedBuilder AddInlineField(string name, object value)
|
public EmbedBuilder AddInlineField(string name, object value)
|
||||||
@@ -107,19 +116,19 @@ namespace Discord
|
|||||||
.WithIsInline(true)
|
.WithIsInline(true)
|
||||||
.WithName(name)
|
.WithName(name)
|
||||||
.WithValue(value);
|
.WithValue(value);
|
||||||
_fields.Add(field);
|
Fields.Add(field);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public EmbedBuilder AddField(EmbedFieldBuilder field)
|
public EmbedBuilder AddField(EmbedFieldBuilder field)
|
||||||
{
|
{
|
||||||
_fields.Add(field);
|
Fields.Add(field);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
public EmbedBuilder AddField(Action<EmbedFieldBuilder> action)
|
public EmbedBuilder AddField(Action<EmbedFieldBuilder> action)
|
||||||
{
|
{
|
||||||
var field = new EmbedFieldBuilder();
|
var field = new EmbedFieldBuilder();
|
||||||
action(field);
|
action(field);
|
||||||
_fields.Add(field);
|
Fields.Add(field);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,9 +136,9 @@ namespace Discord
|
|||||||
{
|
{
|
||||||
_embed.Footer = Footer?.Build();
|
_embed.Footer = Footer?.Build();
|
||||||
_embed.Author = Author?.Build();
|
_embed.Author = Author?.Build();
|
||||||
var fields = ImmutableArray.CreateBuilder<EmbedField>(_fields.Count);
|
var fields = ImmutableArray.CreateBuilder<EmbedField>(Fields.Count);
|
||||||
for (int i = 0; i < _fields.Count; i++)
|
for (int i = 0; i < Fields.Count; i++)
|
||||||
fields.Add(_fields[i].Build());
|
fields.Add(Fields[i].Build());
|
||||||
_embed.Fields = fields.ToImmutable();
|
_embed.Fields = fields.ToImmutable();
|
||||||
return _embed;
|
return _embed;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user