Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord JS – DiscordAPIError: Unknown Message

I get an error:

DiscordAPIError: Unknown Message
    at RequestHandler.execute (D:\Programming\Discord Bot\node_modules\discord.js\src\rest\RequestHandler.js:298:13)        
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (D:\Programming\Discord Bot\node_modules\discord.js\src\rest\RequestHandler.js:50:14)      
    at async MessageManager.delete (D:\Programming\Discord Bot\node_modules\discord.js\src\managers\MessageManager.js:205:5)
    at async Message.delete (D:\Programming\Discord Bot\node_modules\discord.js\src\structures\Message.js:741:5)
    at async AudioPlayer.<anonymous> (D:\Programming\Discord Bot\src\commands\next.js:44:21) {
  method: 'delete',
  path: '/channels/888095042437259287/messages/909879363472855080',
  code: 10008,
  httpStatus: 404,
  requestData: { json: undefined, files: [] }
}

when trying to delete prev. message like this:

await client.message.channel.send({
            content: `Song "${client.currentSong}" is playing`,
            components: [row],
        })
            .then(message => {
                client.player.on(AudioPlayerStatus.Idle, async () => {
                    await message.delete();
                });
            });

This code is executing via one more event code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

client.player.on(AudioPlayerStatus.Idle, () => {
    if (!client.loop) client.playlist.shift();
    if (client.playlist.length === 0) return;
    next.run(client.message, client.args, client);
});

Why does it not work?

>Solution :

You are making an infinite event listener, meaning whenever the audio player goes idle, it will try to delete the message (even if it already got deleted). Change it client.player.once so the listener gets deleted on the first time.

.then(message => {
    client.player.once(AudioPlayerStatus.Idle, async () => {
        await message.delete();
    });
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading