Mxm
Mxm

Reputation: 97

Sequelize and discord.js - How do I turn sequelize info into a simple array

    const gamem = await gamemodes.findAll({attributes: ['name']});
    const newme = await gamemodes.findAll({attributes: ['name']}, {raw: true });
    console.log(newme)
    const mapi = gamem.map(g => g.name).join('\n') || "No Gamemodes yet!";
    await message.channel.send(`Okay! First, choose the gamemode you'd like to search in. List of gamemodes: **${mapi}**. You have 15 seconds, just post your choice here.`)
const msggg = await message.channel.awaitMessages(msg => msg.content == newme.some(), {time: 15000, max: 1});

So, newme is this:

[ gamemodes {
    dataValues: { name: 'Normal' },
    _previousDataValues: { name: 'Normal' },
    _changed: {},
    _modelOptions:
     { timestamps: true,
       validate: {},
       freezeTableName: false,
       underscored: false,
       underscoredAll: false,
       paranoid: false,
       rejectOnEmpty: false,
       whereCollection: null,
       schema: null,
       schemaDelimiter: '',
       defaultScope: {},
       scopes: [],
       indexes: [],
       name: [Object],
       omitNull: false,
       sequelize: [Object],
       hooks: {},
       uniqueKeys: [Object] },
    _options:
     { isNewRecord: false,
       _schema: null,
       _schemaDelimiter: '',
       raw: true,
       attributes: [Array] },
    __eagerlyLoadedAssociations: [],
    isNewRecord: false },

I want to make it like a search function with awaitMessages, so when a user enters a name from the array, it shows other options and info, that's in the rest of the code that I won't show because it's not needed. I want all of the names, and only the names in gamem (and newme) to be entered in a more simple array, but I can't figure it out.

When I run the code above I get this error Invalid value Collection {}

 at Object.escape (D:\BasementMonster\node_modules\sequelize\lib\sql-string.js:66:11)
    at Object.escape (D:\BasementMonster\node_modules\sequelize\lib\dialects\abstract\query-generator.js:934:22)
    at Object.whereItemQuery (D:\BasementMonster\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2141:41)
    at Utils.getComplexKeys.forEach.prop (D:\BasementMonster\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1994:25)
    at Array.forEach (<anonymous>)
    at Object.whereItemsQuery (D:\BasementMonster\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1992:35)
    at Object.getWhereConditions (D:\BasementMonster\node_modules\sequelize\lib\dialects\abstract\query-generator.js:2460:19)
    at Object.selectQuery (D:\BasementMonster\node_modules\sequelize\lib\dialects\abstract\query-generator.js:1140:28)
    at QueryInterface.select (D:\BasementMonster\node_modules\sequelize\lib\query-interface.js:1105:27)
    at Promise.try.then.then.then (D:\BasementMonster\node_modules\sequelize\lib\model.js:1604:34)
    at tryCatcher (D:\BasementMonster\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (D:\BasementMonster\node_modules\bluebird\js\release\promise.js:512:31)
    at Promise._settlePromise (D:\BasementMonster\node_modules\bluebird\js\release\promise.js:569:18)
    at Promise._settlePromise0 (D:\BasementMonster\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (D:\BasementMonster\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (D:\BasementMonster\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (D:\BasementMonster\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues (D:\BasementMonster\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:794:20)
    at tryOnImmediate (timers.js:752:5)
    at processImmediate [as _immediateCallback] (timers.js:729:5)
(node:11156) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11156) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I am sorry for the long post but I've been trying to do this for a few days! Thanks!

Upvotes: 1

Views: 761

Answers (1)

Ashh
Ashh

Reputation: 46481

You need to change the instance to json object using .toJSON()

const newme = await gamemodes.findAll({attributes: ['name']}, {raw: true })
const array = []
newme.map((data) => {
  array.push(data.toJSON())
})

now you can modify the array according to you.

Upvotes: 1

Related Questions