Getting Data from Previous Commands Getting Data from Previous Commands heroku heroku

Getting Data from Previous Commands


This is possible, but there are more practical methods to accomplish your overall problem.

To answer your original question:

  1. Get all messages from the channel.

    TextChannel#messages is an property that contains all the messages in a channel.

  2. Filter out only the messages made by the user who called the command.

    Collection#filter(fn, thisArg) is a method that can filter out values in a collection based on any boolean-returning function fn.

  3. Filter out only the uses of the setBio command.

    Again, we will use Collection#filter.

  4. Get the first value from the collection of messages made by the user.

    Collection#last() is a method that gets the last value in a collection.

  5. Send a prompt, asking the user if they want to use the last bio set.
  6. Await user response.

    There are many ways to do this, but one way it can be done by making another message event, then waiting for a message where the user replies with either "yes" or "no".

So, you can use this piece of code:

case "setBio":    let messages = message.channel.messages;    let authorMessages = messages.filter(m => m.author.id === message.author.id);    let setBioCommands = authorMessages.filter(m => m.content.startsWith(/*insert setBio command                                                                           with prefix here*/);    let firstBio = setBioCommands.last();    // say user prompt, then wait for user to say yes.

However, a better way to approach this problem is to instead store all user data in a separate file, like what @Snel23 said.

This way, all user data will persist, even when the bot is turned off.