Search code examples
javascriptdiscord

Discord.js Dev detector


I am making a discord bot and I have a few dev only commands. However, the system I use to detect if someone is a bot developer doesn't work.

My code:

const { MessageEmbed } = require("discord.js");

exports.execute = async (client, message, args) => {
    if (!client.config.admins.includes(message.author.id)) return message.channel.send("Slow down, poke. This is devs only, poke?"); // return if author isn't bot owner
    let user = message.mentions.users.first();
    if (!user) return message.channel.send("Send money to who?");
    let amount = args[1];
    if (!amount || isNaN(amount)) return message.reply("That isn't a valid amount.");
    let data = client.eco.addMoney(user.id, parseInt(amount));
    const embed = new MessageEmbed()
        .setTitle(`You'll be rich! The money has been added.`)
        .addField(`User`, `<@${data.user}>`)
        .addField(`Balance Given`, `${data.amount} 💸`)
        .addField(`Total Amount`, data.after)
        .setColor("#f54242")
        .setThumbnail(user.displayAvatarURL)
        .setTimestamp();
    return message.channel.send(embed);
}

exports.help = {
    name: "addmoney",
    aliases: ["addbal"],
    usage: `addmoney @user <amount>`
}

I shouldn't have received the devs only message, but when I tested in discord, I did.


Solution

  • Thought I'd just make this an answer than a comment, as I've had time to test.

    This works, but it may be related to how you store your IDs in the admin array.

    .includes() is type sensitive, so a string wont match a number. Discord IDs are a string, so your array has to match it.

    Example:

    const admins = [96876194712018944];
    
    console.log(admins.includes("96876194712018944")); // false