0

I am wondering if there is a way to save a variable from a command like this:

!name nameOfPerson

!age ageOfPerson

and then save it to a database?

What would be a better way to handle this? maybe an array?

André
  • 4,417
  • 4
  • 29
  • 56
Aidan el Goste
  • 383
  • 1
  • 3
  • 23

1 Answers1

0

You might want to try listening on the message event. https://discord.js.org/#/docs/main/stable/class/Message

You can split each message into an array of words, and then add logic for each of your commands based on the first index.

const client = new Discord.Client()

client.on('message', message => {
  let msg = message.content.split(' ') // Split on space

  if (msg[0] === '!age') database_save_logic(message.author, msg[1])
  if (msg[0] === '!name') database_save_logic(message.author, msg[1])
})
Shmish
  • 143
  • 5