'"DiscordAPIError: Unknown Message" when editing existing message

The error message:

throw new DiscordAPIError(data, res.status, request); ^

DiscordAPIError: Unknown Message

keeps popping up. I am trying to make a snake discord game so I am using edit() to imitate frames in a game and when I simply try to use the interaction IU saved from the previous loop,

collector.on('collect', collect => {
    if (collect.isButton()){
        interaction = collect
        pressed = true
    }
})

it says that the interaction has already been reacted to and gives an error. That's why I am trying this way but I can't fix the error or even find it

module.exports = {
    name : 'snake',
    description: 'translate ez',
    async execute(message, MessageActionRow, MessageButton, MessageAttachment){
        const canvas = Canvas.createCanvas(grid*20, grid*20)
        const context = canvas.getContext('2d')

        context.strokeStyle = '#fcfbfc'
        context.strokeRect(0, 0, canvas.width, canvas.height)

        context.strokeRect(snake.head.x*grid, snake.head.y*grid, grid, grid)
        
        var attachment = new MessageAttachment(canvas.toBuffer(), 'snake.png');

        const row = new MessageActionRow()
            .addComponents(
                new MessageButton()
                    .setCustomId('up')
                    .setEmoji("⬆️")
                    .setStyle('PRIMARY'),
                new MessageButton()
                    .setCustomId('left')
                    .setEmoji("⬅️")
                    .setStyle('PRIMARY'),
                new MessageButton()
                    .setCustomId('down')
                    .setEmoji("⬇️")
                    .setStyle('PRIMARY'),
                new MessageButton()
                    .setCustomId('right')
                    .setEmoji("➡️")
                    .setStyle('PRIMARY'),
            );

        message.reply({ files: [attachment], components: [row] })
        .then((Msg)=>{
            msg = Msg
        })
        .catch((err)=>{
            console.error(err)
        })

        const collector = message.channel.createMessageComponentCollector()
        collector.on('collect', collect => {
            if (collect.isButton()){
                interaction = collect
            }
            movement(collect.customId)
            play(canvas, context, attachment, MessageAttachment, row, message, collect)
        })
    }

}

var play = (canvas, context, attachment, MessageAttachment, row, message, collect) =>{
    movement(collect.customId)
    
    var interaction = collect

    context.clearRect(0, 0, canvas.width, canvas.height)

    context.strokeStyle = '#fcfbfc'
    context.strokeRect(0, 0, canvas.width, canvas.height)

    context.strokeRect(snake.head.x*grid, snake.head.y*grid, grid, grid)
    
    attachment = new MessageAttachment(canvas.toBuffer(), 'snake.png');
    
    if (pressed){
        interaction.update({ files: [attachment], components: [row] });
        pressed = false

    }else{
        msg.edit({ files: [attachment], components: [row] })
    }
    

    const collector = message.channel.createMessageComponentCollector()
    collector.on('collect', collect => {
        if (collect.isButton()){
            interaction = collect
            pressed = true
        }
    })

    setTimeout(()=> {
        if(snakeSt){
            play(canvas, context, attachment, MessageAttachment, row, message, interaction)
        }else{
            return
        }
    }, 2000)
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source