I am working on a Node.js application that generates images with custom text using a specific font with canvas, specifically for a Discord bot. I am facing an issue while trying to use a custom font. The font works perfectly fine when it is installed on my local machine (Windows), but I am unable to use it when importing it using the registerFont function.
I think it's worth mentioning that my bot will be hosted on a server, so I won't have control over the fonts installed on the system.
Here is the relevant code snippet:
const { SlashCommandBuilder, AttachmentBuilder } = require("discord.js");
const { createCanvas, registerFont } = require("canvas");
const path = require("node:path");
module.exports = {
data: new SlashCommandBuilder()
.setName("test")
.setDescription("Generate an image"),
async execute(interaction) {
await interaction.deferReply();
const customFontPath = path.join(
__dirname,
"../../../assets/fonts/Impress.ttf"
);
registerFont(customFontPath, { family: "Impress BT" });
const canvas = createCanvas(500, 500);
const ctx = canvas.getContext("2d");
ctx.font = '30px "Impress BT"';
ctx.fillText("Test", 10, 50);
const attachment = new AttachmentBuilder(canvas.createPNGStream(), {
name: `image.png`,
});
await interaction.editReply({
files: [attachment],
});
},
};
This is the image I get when the font is installed on my system: 
This is the image I get when the font is not installed on my system: 
The custom font I'm using: https://www.dafontfree.net/impress-bt-regular/f129654.htm
I have confirmed that the font file is accessible and located at the correct path. However, the text drawn on the canvas does not use the custom font, but falls back to a default font.
I have tried different approaches, including using different font file formats (TTF, OTF), specifying the font file path using absolute and relative paths, checking if the font file is correctly loaded, and using different family names. Unfortunately, none of these attempts have resolved the issue.
It does the same with other custom fonts that aren't installed on my system.
I would greatly appreciate any insights or suggestions on how to successfully use a custom font in a Node.js application for generating images with text.