填满后自动创建一个新的嵌入字段? [VB]
Created a new embed field automatically once one is full? [VB]
Private Async Function cmdList() As Task
Dim m = Context.Message
Dim u = Context.User
Dim g = Context.Guild
Dim c = Context.Client
Dim words As String = ""
Dim embed As New EmbedBuilder With {
.Title = $"Wallpaper keyword list",
.ImageUrl = "https://i.imgur.com/vc241Ku.jpeg",
.Description = "The full list of keywords in our random wallpaper list",
.Color = New Color(masterClass.randomEmbedColor),
.ThumbnailUrl = g.IconUrl,
.Timestamp = Context.Message.Timestamp,
.Footer = New EmbedFooterBuilder With {
.Text = "Keyword Data",
.IconUrl = g.IconUrl
}
}
For Each keyword As String In wall.keywords
words = words + keyword + " **|** "
Next
embed.AddField("Full list", words)
Await m.Channel.SendMessageAsync("", False, embed.Build())
End Function
这是我的命令,用于从数组中获取每个单词并将其放在一个字段中。我想知道的是如何做到这一点,一旦字段填满,它就会自动添加一个新字段并继续列表。这可能有点牵强,但只是不知道如何去做。抱歉,如果我无法理解任何答案。我对 Discord.net 和 vb 的编码还是有点陌生。
这是对你的 hastebin 代码的修改
Dim row As Integer = 0
Dim words As String = String.Empty
For Each keyword As String In wall.keywords
'If appending the keyword to the list of words exceeds 256
'don't append, but instead add the existing words to a field.
If words.Length + keyword.length + 7 > 256 Then
row += 1
embed.AddField($"List #{row}", words) 'Add words to field
'reset words
words = String.Empty
End If
words = words + keyword + " **|** "
Next
'The add condition within the for loop is only entered when we are
'about to exceed to field length. Anything string under the max
'length would exit the loop without being added. Add it here
embed.AddField($"List #{row + 1}", words)
Await m.Channel.SendMessageAsync("", False, embed.Build())
虽然它不会改变任何逻辑,但您可以考虑使用 StringBuilder
Private Async Function cmdList() As Task Dim m = Context.Message Dim u = Context.User Dim g = Context.Guild Dim c = Context.Client Dim words As String = "" Dim embed As New EmbedBuilder With { .Title = $"Wallpaper keyword list", .ImageUrl = "https://i.imgur.com/vc241Ku.jpeg", .Description = "The full list of keywords in our random wallpaper list", .Color = New Color(masterClass.randomEmbedColor), .ThumbnailUrl = g.IconUrl, .Timestamp = Context.Message.Timestamp, .Footer = New EmbedFooterBuilder With { .Text = "Keyword Data", .IconUrl = g.IconUrl } } For Each keyword As String In wall.keywords words = words + keyword + " **|** " Next embed.AddField("Full list", words) Await m.Channel.SendMessageAsync("", False, embed.Build()) End Function
这是我的命令,用于从数组中获取每个单词并将其放在一个字段中。我想知道的是如何做到这一点,一旦字段填满,它就会自动添加一个新字段并继续列表。这可能有点牵强,但只是不知道如何去做。抱歉,如果我无法理解任何答案。我对 Discord.net 和 vb 的编码还是有点陌生。
这是对你的 hastebin 代码的修改
Dim row As Integer = 0
Dim words As String = String.Empty
For Each keyword As String In wall.keywords
'If appending the keyword to the list of words exceeds 256
'don't append, but instead add the existing words to a field.
If words.Length + keyword.length + 7 > 256 Then
row += 1
embed.AddField($"List #{row}", words) 'Add words to field
'reset words
words = String.Empty
End If
words = words + keyword + " **|** "
Next
'The add condition within the for loop is only entered when we are
'about to exceed to field length. Anything string under the max
'length would exit the loop without being added. Add it here
embed.AddField($"List #{row + 1}", words)
Await m.Channel.SendMessageAsync("", False, embed.Build())
虽然它不会改变任何逻辑,但您可以考虑使用 StringBuilder