xixi52 / discord-canvas

A package to simplifie the usage of canvas for Discord !
87 stars 44 forks source link

toBuffer() error #17

Open YoureTrash opened 3 years ago

YoureTrash commented 3 years ago

`const { MessageAttachment } = require("discord.js"); const canvas = require("discord-canvas")

exports.run = async (client, message, args, prefix) => {

let image = new canvas.RankCard() .setAddon("xp", false) .setAddon("rank", false) .setAvatar(message.author.avatarURL) .setLevel(7) .setReputation(450) .setRankName("professional") .setUsername("xixi52") .setBadge(1, "gold") .setBadge(3, "diamond") .setBadge(5, "silver") .setBadge(6, "bronze") .setBackground("https://www.site.com/background.jpg") .toAttachment();

let attachment = new MessageAttachment(image.toBuffer(), "rank-card.png");

message.channel.send(attachment) }

I was testing the npm and when I put the command I get the following error:

(node:2851) UnhandledPromiseRejectionWarning: TypeError: image.toBuffer is not a function

xixi52 commented 3 years ago

Hello sorry for the late ! Use an "await" for the machine have the time to construct canvas before the attachement.

`exports.run = async (client, message, args, prefix) => {

let image = await new canvas.RankCard() .setAddon("xp", false) .setAddon("rank", false) .setAvatar(message.author.avatarURL) .setLevel(7) .setReputation(450) .setRankName("professional") .setUsername("xixi52") .setBadge(1, "gold") .setBadge(3, "diamond") .setBadge(5, "silver") .setBadge(6, "bronze") .setBackground("https://www.site.com/background.jpg") .toAttachment();

let attachment = new MessageAttachment(image.toBuffer(), "rank-card.png");

message.channel.send(attachment) }`

WARNING "https://www.site.com/background.jpg" is not a valid image