Home > other >  All (message).delete() functions push: Unknown Message Error. Discord.js
All (message).delete() functions push: Unknown Message Error. Discord.js

Time:08-21

I'm trying to make a suggestion event in one channel, I'm trying to put many layers of protection on it, trying to test it in many ways ect.. However, after I thought I was done with the testing stage, I was wrong, one of my testers had an issue, each time they tried to send a message that's length is lower than the minimum (25) it seemed to crash, and it confused the sh*t out of me, as I always could do it and nothing happens, I started debugging, and added catch onto every message.delete() function, and guess what, ALL of them bug out, yet, they still delete the message for me, but for Ameer (The Tester) it just crashes without even deleting their message.

I've dealt with a lot of message.delete() problems, but this has been frustrating and confusing.

By the way, I found out ALL of the message.delete() functions delete but still bug out, so it's not an exact one.

Here's the full code:

// Main Requirements \\

const { Secrets, Channels, Guilds, Roles, Permission, Users } = require(`../../config`)
const { QuickDB } = require('quick.db');
const db = new QuickDB();


// Optional Requirements \\

const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js')

const thingstoremove = ["-", "_", ".", ",", "`", "~", "@", "#", "!", "$", "%", "^", "&", "*", "(", ")"]
const blacklistedlinks = ["discord.gg", "bit.ly", "dlscord.com", "discord.com", "discord.net", "nitro-ds.com"]
// whitelistedlinks = [""],
// embedlistedlinks = ["tenor.com"],

// Code \\
module.exports = client => {
    client.on('messageCreate', async message => {
        const channel = message.channel.id === Channels.MAIN_SUGGETIONS
        if (!channel) return;

        if (message.author.bot) return

        if (message.content.includes('-bys')) return;

        var blacklisted = blacklistedlinks;
        var thingstoremovee = thingstoremove;

        const stuff = new RegExp(`[${thingstoremovee.join('')}]`, 'g')

        const args = message.content

        let UserDataSBL = await db.get(`${message.author.id}.SBL`)
        if (UserDataSBL == undefined) UserDataSBL = false
        console.log(UserDataSBL)

        if (UserDataSBL == true) return message.reply(`${message.author}, You're blacklisted from suggesting, please open a ticket to appeal the blacklist.`).then(m => {message.delete().catch(console.log(`Failed to delete, line 38.`)), setTimeout( function() { m.delete() }, 5000)}) 

        // Link protection \\

        try {
            if (message.author.bot) return;
            if (blacklisted.some(word => message.content.toLowerCase().includes(word))) {
                message.reply(`${message.author}, You've been blacklisted for sending blacklisted links!`).then(m => {message.delete().catch(console.log(`Failed to delete, line 45.`)), setTimeout(function() { m.delete() }, 5000)})
                await db.set(`${message.author.id}.SBL`, true)
                return
            } else if (message.content.toLowerCase().replace(stuff, '').includes("https://")) {
                message.reply(`${message.author}, You've been blacklisted for sending links!`).then(m => {message.delete().catch(console.log(`Failed to delete, line 49.`)), setTimeout(function() { m.delete() }, 5000)})
                await db.set(`${message.author.id}.SBL`, true)
                return
        }} catch(e) {
            message.channel.send(`${message.author}, An error has occurred, please talk to support if this continues.`).then(m => {message.delete().catch(console.log(`Failed to delete, line 53.`)), setTimeout( function() { m.delete() }, 5000)})
            return console.log(e)
        }

        // Code \\

        if (message.content.match(/<a?:. ?:\d >/)) return message.reply(`${message.author}, Don't use emojis, they're not allowed while suggesting.`).then(m => {message.delete().catch(console.log(`Failed to delete, line 59.`)), setTimeout( function() { m.delete() }, 5000)}) ;

        if (message.content.replace(/\s/g, '').length < 25) return message.reply(`${message.author}, Please write minimum 25 letters or more.`).then(m => {message.delete().catch(console.log(`Failed to delete, line 61.`)), setTimeout( function() { m.delete() }, 5000)}) 

        if (message.content.replace(/\s/g, '').length >= 25) {
            if (message.content.replace(/\s/g, '').length >= 750) return message.reply(`${message.author}, Please write maximum 750 letters or less.`).then(m => {message.delete().catch(console.log(`Failed to delete, line 64.`)), setTimeout( function() { m.delete() }, 5000)}) 

            const embed = new MessageEmbed()
                .setAuthor({ name: message.author.tag, iconURL: message.author.displayAvatarURL()})
                .setColor("#ffffff")
                .setThumbnail(message.author.avatarURL())
                .setFields(
                    {name: `Suggestion`, value: `\`\`\`${args}\`\`\``},
                )
                .setFooter({ text: `Suggestion by: ${message.author.tag}.\n\Time/Date:`})
                .setTimestamp()

            message.channel.send({ embeds: [embed] }).then(msg => {
                msg.react('949231861853487154')
                msg.react('949232034977558538')
            })

            // Done \\

            try {
                const done = new MessageEmbed()
                .setTitle(`Suggestion submitted!`)
                .setColor("#ffffff")
                .setFields(
                    {name: `Your Suggestion`, value: `\`\`\`${args}\`\`\``},
                )
                .setFooter({ text: `Thank you for suggesting in Voidyy's Planet!\n\nTime/Date:`})
                .setTimestamp()
                await message.author.send({ embeds: [done] }).catch(console.log(`Fail at line 92`))
            } catch (err) {
                console.log(err.name)
            }
            setTimeout(function() {
                return message.delete() 
            }, 5000)
        }
    })
}

Error:

C:\Users\Hamoodi\Desktop\Discord bots\Voidyy's Bot\node_modules\discord.js\src\rest\RequestHandler.js:350

DiscordAPIError: Unknown Message
    at RequestHandler.execute (C:\Users\Hamoodi\Desktop\Discord bots\Voidyy's Bot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\Hamoodi\Desktop\Discord bots\Voidyy's Bot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async MessageManager.delete (C:\Users\Hamoodi\Desktop\Discord bots\Voidyy's Bot\node_modules\discord.js\src\managers\MessageManager.js:212:5)
    at async Message.delete (C:\Users\Hamoodi\Desktop\Discord bots\Voidyy's Bot\node_modules\discord.js\src\structures\Message.js:795:5) {
  method: 'delete',
  path: '/channels/1010336387729461358/messages/1010406288406106172',
  code: 10008,
  httpStatus: 404,
  requestData: { json: undefined, files: [] }
}

Extra Info:

  "dependencies":
    "better-sqlite3": "^7.6.2",
    "discord.js": "^13.10.2",
    "fs": "^0.0.1-security",
    "mongoose": "^6.5.2",
    "ms": "^2.1.3",
    "quick.db": "^9.0.6"
    
    "node": "16.14.2"

Any help would be awesome, man, I hate how unknown message doesn't give you any info on what's the problem, the line or anything.

CodePudding user response:

Discord is a nice place to make bots, But can be frustrating sometimes. Just check if the message exists or not. Also, use the property called deletable given by DJs.

if (message.deletable) message.delete().catch(()=> null);
  setTimeout(() => {
    if (m.deletable) m.delete().catch(() => null);
  }, 5000);

deletable checks Whether the message is deletable by the client user. We are using .catch(() => null); since catching errors isn't really needed here while deleting a message. Discord API throws 10008 only when the message exists no more. Most of the big bots like mine [50k guilds] are likely to follow this while deleting thousands of messages. Silencing this error is the only way. Also, join the official discord.js server for faster responses.

const { Message } = require('discord.js');
function purgeMessage(msg) {
  if (msg instanceof Message && msg.deletable) msg.delete().catch(() => null);
}
  • Related