1
votes
const { RichEmbed, MessageEmbedImage } = require("discord.js");
const { promptMessage } = require("../../functions.js");

module.exports = {
  name: "bugreport",
  aliases: ["bugreports"],
  usage: "bugreport <your report>",
  description: "Send your report",
  category: "server",
  run: async (client, message, args) => {
    const channel = message.guild.channels.find(c => c.name === "「❗」reports");

    if (message.deletable) message.delete();
    
    if(!args[0]) {
        return message.reply("Please write your report").then(m => m.delete(10000));
        }
    if(!channel) {
      return message.reply("There is no channel with name '#「❗」reports'").then(m => m.delete(10000));
        }
        
    const bugreportMessage = {
      color: 51199,
      author: {
        name: "Report created by "+message.author.username,
        icon_url: message.author.avatarURL
      },
      title: "New bug reported:",
      url: "",
      description: args.slice(0).join(" "),
      thumbnail: {
        url: message.author.avatarURL,
      },
      timestamp: new Date(),
      footer: {
        icon_url: client.user.avatarURL, text: "♛ Space Network"
      }
    }

    message.channel.send("Sending your report to " + channel).then(m => m.delete(10000))
    await channel.send({ embed: bugreportMessage });
    }
}

Error: (node:8420) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message at E:\GitHub\space-bot\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15 at E:\GitHub\space-bot\node_modules\snekfetch\src\index.js:215:21 at processTicksAndRejections (internal/process/task_queues.js:93:5) (Use node --trace-warnings ... to show where the warning was created) (node:8420) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:8420) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Discord when running the command: enter image description here

Console after run command: enter image description here

1
Just a heads up, DJS v11 is no longer being maintained or supported and will soon no longer work with the Discord API. I highly recommend updating to the current stable version v12 as upcoming v13 is soon to arrive. You wouldn't want to get left behind.Elitezen

1 Answers

0
votes

There are quite a few methods in your code that return promises and I can't see any catch()es to handle rejections. I think one of those .delete()s can't find the message you want to delete.

If you're already using an async function, you could get rid of those then()s and use async-await instead, and wrap your code in a try-catch block like this:

run: async (client, message, args) => {
  try {
    const channel = message.guild.channels.find(
      (c) => c.name === '「❗」reports',
    );

    if (message.deletable) message.delete();

    if (!args[0]) {
      const msg = await message.reply('Please write your report');
      return msg.delete(10000);
    }

    if (!channel) {
      const msg = await message.reply("There is no channel with name '#「❗」reports'");
      return msg.delete(10000);
    }

    const bugreportMessage = {
      color: 51199,
      author: {
        name: 'Report created by ' + message.author.username,
        icon_url: message.author.avatarURL,
      },
      title: 'New bug reported:',
      url: '',
      description: args.slice(0).join(' '),
      thumbnail: {
        url: message.author.avatarURL,
      },
      timestamp: new Date(),
      footer: {
        icon_url: client.user.avatarURL,
        text: '♛ Space Network',
      },
    };

    const msg = await message.channel.send('Sending your report to ' + channel);
    msg.delete(10000);

    channel.send({ embed: bugreportMessage });
  } catch (error) {
    console.log(error);
  }
};