Создали новое поле для встраивания автоматически, когда оно заполнено? [ВБ]

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.


person SOPMOD    schedule 25.12.2020    source источник
comment
при построении строки слов проверьте, не приведет ли длина добавляемого нового слова к превышению максимальной длины поля строки. Если оно превысит, не добавляйте его в строку, а вместо этого добавьте строку в поле... сбросьте words, используя новое слово, продолжайте ту же логику, пока не закончите.   -  person Anu6is    schedule 25.12.2020
comment
это будет интересно выяснить. Не уверен, как это сделать.   -  person SOPMOD    schedule 25.12.2020
comment
hastebin.com/ixaqubelat.php Из моей попытки. Не уверен, что именно мне нужно было сделать.   -  person SOPMOD    schedule 26.12.2020


Ответы (1)


Это модификация вашего кода 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

person Anu6is    schedule 26.12.2020