javascript - 为什么 repl.it 不能加载默认字体配置?
问题描述
信息:在此文件中使用 NodeJS、Discord.js 和画布,以及 repl.it 托管。
此代码在我的本地计算机上运行,但在移至 repl.it 托管它时,我收到错误“Fontconfig 错误:无法加载默认配置文件”代码如下
const Canvas = require('canvas')
const { MessageAttachment } = require('discord.js')
const path = require('path')
module.exports = (client) => {
client.on('guildMemberAdd', async (member) => {
const { guild } = member
const channelId = "830958927674998815"
if (!channelId) {
return
}
const channel = guild.channels.cache.get(channelId)
if (!channel) {
return
}
const canvas = Canvas.createCanvas(700, 250)
const ctx = canvas.getContext('2d')
const background = await Canvas.loadImage(
path.join(__dirname, '../background.png')
)
let x = 0
let y = 0
ctx.drawImage(background, x, y)
const pfp = await Canvas.loadImage(
member.user.displayAvatarURL({
format: 'png',
})
)
x = canvas.width / 2 - pfp.width / 2
y = 25
ctx.drawImage(pfp, x, y)
ctx.fillStyle = '#ffffff'
ctx.font = '35px sans-serif'
let text = `Welcome ${member.user.tag}`
x = canvas.width / 2 - ctx.measureText(text).width / 2
ctx.fillText(text, x, 60 + pfp.height)
ctx.font = '30px sans-serif'
text = `Member #${guild.memberCount}`
x = canvas.width / 2 - ctx.measureText(text).width / 2
ctx.fillText(text, x, 100 + pfp.height)
const attachment = new MessageAttachment(canvas.toBuffer())
channel.send('', attachment)
})
}```
解决方案
推荐阅读
- parsing - 使用 Sablecc 转移/减少冲突
- sql - 删除行块postgres
- java - cardview不显示cornerRadius和海拔
- c# - 如何在 C# 中将对象添加到没有引用的对象列表中?
- vba - VBA 调暗和设置范围全局
- javascript - ENCODING_ERR 带有 Ionic 文件插件的 Javascript Blob
- html - 文件下载并通过VBA打开
- javascript - JavaScript 数组作为 ref 传递但不能将 ref 分配给新数组?
- c# - 将 datetime2 数据类型转换为 datetime 数据类型异常,日期在 1753/1/1 之后
- python - WALS Model Tensorflow - 为新用户获取推荐