Search code examples
discorddiscord.jseval

Eval command doesn't work at all, but it doesn't error


I'm trying to make an eval command for my bot. It doesn't error, but it doesn't send a message to the console or the discord channel. Heres my eval code:

const clean = async (client, text) => {
  if (text && text.constructor.name == "Promise")
    text = await text;
  if (typeof text !== "string")
    text = require("util").inspect(text, { depth: 1 });
  text = text
    .replace(/`/g, "`" + String.fromCharCode(8203))
      .replace(/@/g, "@" + String.fromCharCode(8203));
  text = text.replaceAll(client.token, "[REDACTED]");
  return text;
}

client.on("messageCreate", async (message) => {
  const args = message.content.split(" ").slice(1);

  if (message.content.startsWith(`${p}eval`)) {
    if (message.author.id !== 821682594830614578) {
      return;
    }
    
    try {
      const evaled = eval(args.join(" "));
      const cleaned = await clean(client, evaled);

      message.channel.send(`\`\`\`js\n${cleaned}\n\`\`\``);
    } catch (err) {
      message.channel.send(`\`ERROR\` \`\`\`xl\n${cleaned}\n\`\`\``);
    }

  }

});

Solution

  • It seems like you put a number as your ID... Discord.js IDs are in strings so you should put your ID into a string.

        if (message.author.id !== "821682594830614578") {
          return;
        }