'Discord.JS & Sequelize integration

I've been building a discord bot over the last few weeks just as a side project. I've built a fair amount as i've been working through the various tutorials in Discordjs.guide.

I've come to the Sequelize section of the tutorial and worked through it, ok all makes perfect sense to me.

Instead of creating a new bot file, i've been trying to incorporate it into everything i've built already. Being a little bit of a novice i've tried to make sense of how to do that with everything that was in the previous sections, but some of the code doesn't match up to the bot that has been built up until this point.

Now i feel like i'm getting there after a lot of reading and some trial an error, but i'm missing something, or i don't quite understand what i'm writing and i've hit a dead end and need some help.

I've worked through this page. - https://discordjs.guide/sequelize/#a-simple-tag-system

I've incorporated the Alpha, Beta & Gamma into my index.js file that was originally created at the start of the guide.

I've then taken the "Delta, Epsilon Etc" and split them into their own command files as shown previously in the tutorial.

I've also got the reload command that is previously in the tutorial.

So, my bot runs fine, i can use my previous commands for things like telling a joke, or showing a avatar.

But when i try to use any of the "addTag", "editTag" nothing happens, when i try to reload these commands, my bot tells me the command doesnt exist, but when i do my help command these commands are displayed in the dynamic command menu.

I've got a feeling i'm missing something makes the module export as async functions?

If anyone could explain what im doing wrong, or just point me in the right direction i would be grateful and if you need me to provide anything else let me know! Thank you.

Index.js

    const fs = require('fs');

    const Discord = require('discord.js');

    const { prefix, token } = require('./config.json');

    const client = new Discord.Client();

    client.commands = new Discord.Collection();

    const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

    for (const file of commandFiles) {
    const command = require(`./commands/${file}`);

    client.commands.set(command.name, command);
    }

    const cooldowns = new Discord.Collection();
    const Sequelize = require('sequelize');

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

const Tags = sequelize.define('tags', {
    name: {

    type: Sequelize.STRING,

    unique: true,
    },
    description: Sequelize.TEXT,
    username: Sequelize.STRING,
    usage_count: {
        type: Sequelize.INTEGER,
        defaultValue: 0,
        allowNull: false,
},
});
    client.on('ready', async () => {
    Tags.sync();
    console.log(`Logged in as ${client.user.tag}!`);
    client.user.setActivity('for souls.', { type: 'WATCHING' });

    })

    client.on('message', async message => {

    if (!message.content.toLowerCase().startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);

    const commandName = args.shift().toLowerCase();
    const commandArgs = args.join(' ');

    const command = client.commands.get(commandName) ||
        client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
        if (!command) return;

    if (command.guildOnly && message.channel.type != 'text') {
        return message.reply ('I can\'t do this here, you filthy human.');
    }
    if (command.args && !args.length) {
    let reply = `Well, you gotta tell me what to do?!`;
    if (command.usage) {
    reply += `\nDo it properly, imbecile. \`${prefix}${command.name} ${command.usage}\``;
    }
    return message.channel.send(reply);
    }
    if (!cooldowns.has(command.name)) {
    cooldowns.set(command.name, new Discord.Collection());
    }

    const now = Date.now();

    const timestamps = cooldowns.get(command.name);

    const cooldownAmount = (command.cooldown || 3) * 1000;

    if (timestamps.has(message.author.id)) {

        const expirationTime = timestamps.get(message.author.id) + cooldownAmount;
        if (now < expirationTime) {

            const timeLeft = (expirationTime - now) / 1000;

            return message.reply(`Slow down, you/'ve got all life....Heh heh heh.`);
        }

    }
    timestamps.set(message.author.id, now);
    setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
    try {
    command.execute(message, args);
    } catch (error) {
    console.error(error);
    message.reply('I can/t do that, mortal. ')
    }
});
client.login(token);
process.on('unhandledRejection', error => {
console.error('Unhandled promise rejection:', error);
});

command-addTag.Js

const { prefix } = require('../config.json');
    const Sequelize = require('sequelize');

const Discord = require('discord.js');

module.exports  =  {

name: 'addTag',
description:'Adds a tag to the user in the database',
args: true,
cooldown: 10,

execute(message, args) {
    (async() => {

    try {

        const tag = await Tags.create({
            name: tagName,
            description: tagDescription,
            username: message.author.username
        });
        return message.reply(`Tag ${tag.name} added.`)
    }

    catch (e) {

        if (e.name === 'SequelizeUniqueConstaintError') {
            return message.reply('That tag already exists.');
        }
        return message.reply('Something went wrong with adding a tag.');
    }
})();
}
};


Solution 1:[1]

This is a bit late, but here is what I think you need to add.

client.once('ready', () => {
  Tags.sync();

  console.log(`Logged in as ${client.user.tag}!`);
});

You can get more at https://discordjs.guide/sequelize/#creating-the-model

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P