gpt4 book ai didi

sequelize.js - Sequelize 和 discord.js - 如何将 sequelize 信息转换为简单数组

转载 作者:行者123 更新时间:2023-12-03 22:20:03 29 4
gpt4 key购买 nike

    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});

所以, newme 是这样的:
[ 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 },

我想让它像一个带有 awaitMessages 的搜索函数,所以当用户从数组中输入一个名称时,它会显示其他选项和信息,这是我不会显示的其余代码,因为它不需要。我希望所有的名字,只有在 gamem(和 newme)中的名字被输入到一个更简单的数组中,但我无法弄清楚。

当我运行上面的代码时,我收到此错误 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.

我很抱歉这篇很长的帖子,但我已经尝试这样做了几天!谢谢!

最佳答案

您需要使用 .toJSON() 将实例更改为 json 对象

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

现在你可以根据你修改 array 了。

关于sequelize.js - Sequelize 和 discord.js - 如何将 sequelize 信息转换为简单数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50446906/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com