Font generator in discord.js

Viewed 869

I am currently working on a small discord.js project and I'm wondering how I would convert a message to a fancy font.
I have tried the following code:

module.exports = async (args, message) => {
 var lines = ['', '', '', '', '', ''];
 var starter = '➳';
 var letters = {
  a: '',
  b: '',
  c: '',
  d: '',
  e: '',
  f: '',
  g: '',
  h: '',
  i: '',
  j: '',
  k: '',
  l: '',
  m: '',
  n: '',
  o: '',
  p: '',
  q: '',
  r: '',
  s: '',
  t: '',
  u: '',
  v: '',
  w: '',
  y: '',
  x: '',
  z: '',
 };

 if (!args[0]) {
  message.reply('Please specify a message.');
 } else {
  console.log(args.join(' ').length);
  message.channel.send(starter + args.slice(0).join(' '));

  for (var i = 0; i < args.join(' ').length; i++) {
   var letter = args.join(' ')[i].toLowerCase();
   for (var j = 0; j < 6; j++) {
    lines[j] += letters[letter][j] + '   ';
   }
  }
  console.log(lines);
  message.channel.send(lines.join('\n'));
 }
};

The code works fine up until for (var j = 0; j < 6; j++) { lines[j] += letters[letter][j] + ' '; } I was just wondering how I would go on getting these characters in the font I have specified.
Example:
~font text"
output:
➳test
undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined undefined

1 Answers

I've noticed that your json object is only one layer 'thick' (not entirley sure the correct way to say that) meaning that trying to access the second layer causes the undefined error you are describing. To rectify this change:

for (var j = 0; j < 6; j++) {
    lines[j] += letters[letter][j] + '   ';
}

to

for (var j = 0; j < 6; j++) {
    lines[j] += letters[letter] + '   ';
}
Related