Accessing elements inside a returned sequelize object

In my messageReactionAdd.js file I'm trying to just get the value of one of the properties in the returned object from my query. How can I pull the value myDiscordUsername from the returned query object? /utils/database.js
const Sequelize = require('sequelize');

const sequelize = new Sequelize('database', 'user', 'password', {
dialect: 'sqlite',
host: 'localhost',
storage: 'database.sqlite',
logging: false,
transactionType: 'IMMEDIATE',
});

module.exports = sequelize;
const Sequelize = require('sequelize');

const sequelize = new Sequelize('database', 'user', 'password', {
dialect: 'sqlite',
host: 'localhost',
storage: 'database.sqlite',
logging: false,
transactionType: 'IMMEDIATE',
});

module.exports = sequelize;
/models/game_user.js
const Sequelize = require('sequelize');
const sequelize = require('../utils/database');

const GameSession = sequelize.define(
'game_user', {
id: {
type: Sequelize.BIGINT(20),
primaryKey: true,
autoIncrement: true,
},
discordId: {
type: Sequelize.STRING,
allowNull: false,
},
},
{
initialAutoIncrement: 1000,
},
);

module.exports = GameSession;
const Sequelize = require('sequelize');
const sequelize = require('../utils/database');

const GameSession = sequelize.define(
'game_user', {
id: {
type: Sequelize.BIGINT(20),
primaryKey: true,
autoIncrement: true,
},
discordId: {
type: Sequelize.STRING,
allowNull: false,
},
},
{
initialAutoIncrement: 1000,
},
);

module.exports = GameSession;
/events/messageReactionAdd.js
const { Events } = require('discord.js');
const GameUsers = require('../models/game_user');

module.exports = {
name: Events.MessageReactionAdd,
async execute(reaction, user) {
if (user.bot) {
return;
}

// Get the current user's id
let userId = null;
const user_current = await GameUsers.findOrCreate(
{
where: {
discordId: user.username,
},
},
)
.then((gameUser) => {
console.log(gameUser);
// console.log(userId);
});
},
};
const { Events } = require('discord.js');
const GameUsers = require('../models/game_user');

module.exports = {
name: Events.MessageReactionAdd,
async execute(reaction, user) {
if (user.bot) {
return;
}

// Get the current user's id
let userId = null;
const user_current = await GameUsers.findOrCreate(
{
where: {
discordId: user.username,
},
},
)
.then((gameUser) => {
console.log(gameUser);
// console.log(userId);
});
},
};
3 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
armega
armega8mo ago
RETURNED OBJECT
[
game_user {
dataValues: {
id: 1,
discordId: 'myDiscordUsername',
createdAt: 2024-02-05T23:59:13.235Z,
updatedAt: 2024-02-05T23:59:13.235Z
},
_previousDataValues: {
id: 1,
discordId: 'myDiscordUsername',
createdAt: 2024-02-05T23:59:13.235Z,
updatedAt: 2024-02-05T23:59:13.235Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
false
]
[
game_user {
dataValues: {
id: 1,
discordId: 'myDiscordUsername',
createdAt: 2024-02-05T23:59:13.235Z,
updatedAt: 2024-02-05T23:59:13.235Z
},
_previousDataValues: {
id: 1,
discordId: 'myDiscordUsername',
createdAt: 2024-02-05T23:59:13.235Z,
updatedAt: 2024-02-05T23:59:13.235Z
},
uniqno: 1,
_changed: Set(0) {},
_options: {
isNewRecord: false,
_schema: null,
_schemaDelimiter: '',
raw: true,
attributes: [Array]
},
isNewRecord: false
},
false
]
npm list ── discord.js@14.14.1
treble/luna
treble/luna8mo ago
Not djs related, #other-js-ts
Want results from more Discord servers?
Add your server