If you take a closer look at the sentence structures between 借喻 and 借代, the differences could be easily told.
We use 借喻 to describe the object ''like something else''. The key indicators of 借喻 are 1. Whether we mention the subject clearly. 2. Whether there is any:像是, 像, 跟...一樣... etc in the sentence.
On another hand, 借代 is to describe an object without clearly mentioning the name of it, but replace it with another thing that the object looks like.
The sentence: 黑帽子一言不发，把趴在桌子睡觉的懒虫拉了起来。 Q: Is there any 像是, 像, 跟...一樣... in the sentence? A: No Q: Does the sentence clearly mentioned who's sleeping on the desk? A: No, it used ''lazy worm'' instead of the person's name or identification. Therefore, it uses 借代 in the sentence.
Please do not hesitate to reach out if you have further questions like this! I'm happy to explain more in class!