0

I've created an ascii table using ascii-table3 that gets posted to discord. The table gets posted no problem with no issues like in pic below, but I'm trying to integrate colors to the table, but can't seem to get that part working. As far as I know colors only work with code blocks so I'm using inlineCode from @discordjs/builders to put the ascii table inside of, but it doesn't seem to recognize the markdown language. When I try to add markdown language it breaks the table like this when doing table.addRow('```diff\n+' + position.value + 'n\n```') for a row. Adding newLines does seem problematic though with ascii-table3 so perhaps there's a better way...

enter image description here

So my question is how can I build a table in discord and add colors? Maybe a different library or my syntax might be off, but I don't think it is. I know that markdown syntax is sensitive to things like spaces though so maybe that is the problem... I appreciate any help!

UPDATED

  for (let position of positions) {

         table.addRow(
            position.value,
            position.value,
            position.value,
            position.value,
            position.value,
            position.value,
            '+' + position.value
        );
    }
    table.setAlign(1, AlignmentEnum.CENTER);
    table.setAlign(2, AlignmentEnum.CENTER);
    table.setAlign(3, AlignmentEnum.CENTER);
    table.setAlign(4, AlignmentEnum.CENTER);
    table.setAlign(5, AlignmentEnum.CENTER);
    table.setAlign(6, AlignmentEnum.CENTER);
    table.setAlign(7, AlignmentEnum.CENTER);

    table.setStyle('unicode-single');

    return inlineCode('```diff\n' + table.toString() + '```');

[![enter image description here][3]][3]

enter image description here

6
  • i think your issue is trying to put color within a certain line. AFAIK, you have to do this in multi-line code blocks to get colorization to work. for example, setup your whole text string, and prepend ` ` ` json\n and postpend ` ` ` (no spaces on the ticks) to it and you'll get a color block. Commented Jan 4, 2023 at 19:24
  • Not sure I fully get what you mean, but I think so. I added an updated section to reference change on what I think you meant, but doesn't do what I need yet. Commented Jan 4, 2023 at 21:09
  • this is doing this per row....I'm saying do this before and after the table buid. You're still trying to do it a row at a time. Commented Jan 6, 2023 at 15:14
  • @G-Force I updated the UPDATED example. I wanna say this is what you meant. If so, then that didn't work either. As you can see I added a + to the last row to try and highlight that column. If this isn't what you meant, can you provide an example of what you mean? Commented Jan 7, 2023 at 3:41
  • it's what I meant...you're using diff, I mentioned json....but it's not the issue. there is an extra '`' showing on the beginning and ending, I'm guessing from your formatter. try using 2 instead of 3 ticks? also using diff, you can see it is intended for +/-, see this stackoverflow.com/questions/40883421/… as an example. Commented Jan 7, 2023 at 19:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.