armega
armega
DIAdiscord.js - Imagine an app
Created by armega on 2/6/2024 in #djs-questions
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);
});
},
};
5 replies