'How do I make a command in Discord bot in js that insert data in a database with Sequelize?
I'm working on a Discord bot using node.js modules and Sequelize to database, and I want to add a command that users type and the bot registers them in database. This is the code so far:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { User } = require('discord.js');
const tableData = require('../config/tableData');
module.exports = {
data: new SlashCommandBuilder()
.setName('Registro')
.setInfo('Cria uma conta bancária no nosso banco de dados!'),
async execute(interaction) {
function insertData() {
const newData = tableData.create({
name: `${User.id}`,
saldo: 0,
farm: false,
});
return newData;
}
await interaction (insertData());
},
};
But I really don't know why it's not working. First I have one file for the creation of database and the definition of the table to use, but when I export both, my bot throws an error that says it is not able to connect to my database. So I created a single file for each one and tried to connect, but honestly, I have no idea what I have to do.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|