Search code examples
javascriptdiscord.js

Discord.js Command out right refuses to work


I want to make a command that is set to enabled by default and after the user uses it once it sets to disabled by default. Also that the command is disabled per-user. But when executing this code it out right refuses to work and i get no error in the terminal. Any help would be appriciated!

Heres my Code so far:

const { Client, Message, MessageEmbed } = require('discord.js');
const { QuickDB } = require('quick.db');
const db = new QuickDB();

module.exports = {
    name: 'alert',
    /** 
     * @param {Client} client 
     * @param {Message} message 
     * @param {String[]} args 
     */
    run: async(client, message, args) => {
        let embed = new MessageEmbed()
                .setTitle("🎉It seems you are new here!")
                .setDescription("Use `R2 set help` to get help setting up your profile!\nUse `R2 help` to see all commands catagorized.\n\n**Pro Tip:🤫** Use `R2 help` followed by the command name for more information!")
                .setColor("#2F3136")
                .setTimestamp()
        if(db.get(`${message.author.id}alert_`) !== true){
            return;
        } else if(db.get(`${message.author.id}alert_`) !== false){
            message.channel.send({embeds: [embed]})
            db.set(`${message.author.id}alert_`, false)
            }
        }
    }

Solution

  • const { QuickDB } = require("quick.db");
    const db = new QuickDB();
    
    run: async(client, message, args) => {
        if(await db.get(`${message.author.id}.alert` == true)) return;
        
        // Message Embed Code
    
        message.channel.send( . . . );
    
        await db.set(`${message.author.id}.alert`, true);
    }

    Should work for you, it seems like quick.db requires a dot between values, as it has a JSON structure. You can view the documentation for it here.

    https://quickdb.js.org/