Home > Blockchain >  Unsupported Image type?
Unsupported Image type?

Time:01-26

My Code index.js

const Discord = require("discord.js")
require("dotenv").config()

const Image = require("./Image")

const Token = "*MY TOKEN*"
const client = new Discord.Client({
    intents: [
        "GUILDS",
        "GUILD_MESSAGES",
        "GUILD_MEMBERS"
    ]
})

client.on("ready", () =>{
    console.log(`Logged in as ${client.user.tag}`)
})

client.on("messageCreate", (message) => {
    if (message.content == "hi!"){
        message.reply("Hello")
    }
})

const welcomeChannelID = "935422032458444901"

client.on("guildMemberAdd", async (member) =>{
    const img = await Image(member)
    member.guild.channels.cache.get(welcomeChannelID).send({
        content:`<@${member.id}> Welcome to the Server!`,
        files: [img]
    })
})

client.login(Token)

image.js

const Canvas = require("canvas")
const Discord = require("discord.js")
const background = "https://ibb.co/c3YYzgw"
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

ERROR

PS D:\DBS> node index.js
Logged in as XGaming Test Bot#1095
D:\DBS\node_modules\canvas\lib\image.js:91
  SetSource.call(img, src)
            ^

Error: Unsupported image type
    at setSource (D:\DBS\node_modules\canvas\lib\image.js:91:13)
    at D:\DBS\node_modules\canvas\lib\image.js:59:11
    at D:\DBS\node_modules\simple-get\index.js:89:7
    at PassThrough.<anonymous> (D:\DBS\node_modules\simple-concat\index.js:8:13)
    at Object.onceWrapper (node:events:509:28)
    at PassThrough.emit (node:events:390:28)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

I am getting an error whenever I join with my alt account in the server, it is saying hello when I type hi!. but is not giving a message when a user joins my server. At first it was giving a welcome message [when I didn't add Image] now it is not even showing text. .......................................................

CodePudding user response:

Your "image" in your Image.js is a HTML, not Image.

You need to replace

const background = "https://ibb.co/c3YYzgw"

with

const background = "https://i.ibb.co/02ssPDK/Music-1200x670.png"

To get the correct image link, just click RMB on the image and select "Copy Image URL".

  •  Tags:  
  • Related