Discord.js 会员图片未显示
Discord.js Member Image not showing
我的代码
const Canvas = require("canvas")
const Discord = require("discord.js")
const background = "https://i.ibb.co/02ssPDK/Music-1200x670.png"
const dim = {
height: 675,
width: 1200,
margin: 50
}
const av = {
size: 256,
x: 480,
y: 170
}
const Image = async (member) => {
let username = member.user.username
let discrim = member.user.discriminator
let avatarURL = member.user.displayAvatarURL({format: "png", dynamic: false, size: av.size})
const canvas = Canvas.createCanvas(dim.width, dim.height)
const ctx = canvas.getContext("2d")
//Draw
const backgimage = await Canvas.loadImage(background)
ctx.drawImage(backgimage, 0, 0)
//Black box
ctx.fillStyle = "rgba(0,0,0,0.8)"
ctx.fillRect(dim.margin, dim.margin, dim.width - 2 * dim.margin, dim.height - 2 * dim.margin)
const avimg = await Canvas.loadImage(avatarURL)
ctx.save()
ctx.beginPath()
ctx.arc(av.x + av.size /2, av.h + av.size /2, av.size/2, 0, Math.PI*2, true)
ctx.closePath()
ctx.clip()
ctx.drawImage(avimg, av.x, av.y)
ctx.restore()
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), "welcome.png")
return attachment
}
module.exports = Image
DaError
当用户加入我的频道时,只有背景图片和文字出现,而没有用户的图像。
..................................................... ..................................................... ..................................................... .....................
根据您的代码:ctx.arc(av.x + av.size /2, av.h + av.size /2, av.size/2, 0, Math.PI*2, true)
您应该键入 av.y
而不是 av.h
,因为在 av
变量中,它不包含 h
.
我的代码
const Canvas = require("canvas")
const Discord = require("discord.js")
const background = "https://i.ibb.co/02ssPDK/Music-1200x670.png"
const dim = {
height: 675,
width: 1200,
margin: 50
}
const av = {
size: 256,
x: 480,
y: 170
}
const Image = async (member) => {
let username = member.user.username
let discrim = member.user.discriminator
let avatarURL = member.user.displayAvatarURL({format: "png", dynamic: false, size: av.size})
const canvas = Canvas.createCanvas(dim.width, dim.height)
const ctx = canvas.getContext("2d")
//Draw
const backgimage = await Canvas.loadImage(background)
ctx.drawImage(backgimage, 0, 0)
//Black box
ctx.fillStyle = "rgba(0,0,0,0.8)"
ctx.fillRect(dim.margin, dim.margin, dim.width - 2 * dim.margin, dim.height - 2 * dim.margin)
const avimg = await Canvas.loadImage(avatarURL)
ctx.save()
ctx.beginPath()
ctx.arc(av.x + av.size /2, av.h + av.size /2, av.size/2, 0, Math.PI*2, true)
ctx.closePath()
ctx.clip()
ctx.drawImage(avimg, av.x, av.y)
ctx.restore()
const attachment = new Discord.MessageAttachment(canvas.toBuffer(), "welcome.png")
return attachment
}
module.exports = Image
DaError
当用户加入我的频道时,只有背景图片和文字出现,而没有用户的图像。 ..................................................... ..................................................... ..................................................... .....................
根据您的代码:ctx.arc(av.x + av.size /2, av.h + av.size /2, av.size/2, 0, Math.PI*2, true)
您应该键入 av.y
而不是 av.h
,因为在 av
变量中,它不包含 h
.