1
votes

I am trying to get some info from the message and show it in an embed. But when I run this code I get something like this:

enter image description here

Here is my code:

run: async (client, message, args) => {
  async function getinfo() {
    let lol1 = args[1]
    let lol2 = args.slice(2).join(' ')

    const whois = new Discord.MessageEmbed()
      .setTitle("test1:")
      .addField("test2", ` ${lol1} / ${lol2}`)
      .setColor("RANDOM")
      .setTimestamp()

    message.channel.send(whois)
  }
  getinfo();
}
1

1 Answers

0
votes

How are arguments defined?

The definition of arguments in discord.js is any user input after the command itself. So, if we look at the basic template of how arguments look like:

[Prefix][Command] [args]

Meaning that 'args' already splits off the prefix and the command already, living us with the args variable, who is basically an array of the arguments provided:

const args = ['first argument', 'second argument', 'third argument', ...];

From this logic, when you're inserting '123' and '123' as your arguments, we're getting the following array:

const args = ['123', '123'];

And since we're always starting at 0 when getting array values, the first '123' would be referred to as args[0] while the second '123' would be referred to as args[1].

Final Code

run: async (client, message, args) => {

        async function getinfo() {
        let lol1 = args[0];
        let lol2 = args.slice(1).join(' ');
    
    
        const whothefuq = new Discord.MessageEmbed()
              .setTitle("test1:")
              .addField("test2", ` ${lol1} / ${lol2}`)
              .setColor("RANDOM")
              .setTimestamp()
          message.channel.send(whothefuq)
        
        }
    
        getinfo();
    }