Home > Blockchain >  Discord JS - DiscordAPIError: Unknown Message
Discord JS - DiscordAPIError: Unknown Message

Time:11-16

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:

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?

CodePudding user response:

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();
    });
})
  • Related