3

This function its not working. I tried a lot of things and nothing,i think its the "guildMemberAdd".

client.on("guildMemberAdd", async member => {

  let canal = client.channels.get(config.welcome)
  let fonte = await jimp.loadFont(jimp.FONT_SANS_32_BLACK)
  let mask = await jimp.read('mascara.png')
  let fundo = await jimp.read('fundo.png')
  
  jimp.read(member.user.displayAvatarURL).then(avatar => {
  avatar.resize(130, 130)
  mask.resize(130, 130)
  avatar.mask(mask)

  fundo.print(fonte, 170, 175, member.user.username)
  fundo.composite(avatar, 40, 90).write('bemvindo.png')
  canal.send(`Welcome !`, { files: ["bemvindo.png"] })
  
  console.log('Imagem enviada para o Discord')
  })
  .catch(err => {
  console.log('error avatar')
  })
});

Detail, the bot works, just the jimp part dont work

If someone know why dont work, pls tell me.

Toasty
  • 1,850
  • 1
  • 6
  • 21
Envyus
  • 31
  • 1

1 Answers1

2

I think the issue is because you have Discord.js v11 code but you're running the bot with Discord.js v12.

client.channels.get(config.welcome) should now be client.channels.cache.get(config.welcome).

Fixed code below:

client.on("guildMemberAdd", async member => {

  let canal = await client.channels.fetch(config.welcome)
  let fonte = await jimp.loadFont(jimp.FONT_SANS_32_BLACK)
  let mask = await jimp.read('mascara.png')
  let fundo = await jimp.read('fundo.png')
  
  jimp.read(member.user.displayAvatarURL({format: 'png'})).then(avatar => {
  avatar.resize(130, 130)
  mask.resize(130, 130)
  avatar.mask(mask)

  fundo.print(fonte, 170, 175, member.user.username)
  fundo.composite(avatar, 40, 90).write('bemvindo.png')
  await canal.send(`Welcome !`, { files: ["bemvindo.png"] })
  
  console.log('Imagem enviada para o Discord')
  })
  .catch(err => {
  console.log('error avatar')
  })
});
Thunder
  • 461
  • 2
  • 6
  • i using discord "discord.js": "^12.0.0", that means discord v12 :/ – Envyus Jul 27 '21 at 15:17
  • anf if i put "client.channels.cache.get" gives me error of jimp ```Error: No matching constructor overloading was found.``` – Envyus Jul 27 '21 at 15:20
  • Can you try upgrading to Discord.js v12.5.3? – Thunder Jul 27 '21 at 19:17
  • same error ```No matching constructor overloading was found``` – Envyus Jul 27 '21 at 22:43
  • I realized my error, there were supposed to be parentheses after `displayAvatarUrl`. The code should be fixed and should work now. – Thunder Jul 28 '21 at 03:03
  • It wasn't working since in Discord.js v12 `displayAvatarURL` is now a function. Because your code didn't have parentheses, it wasn't returning a valid URL, so Jimp was returning an error. – Thunder Jul 28 '21 at 03:09
  • That error its fixed, but now i have another, i change "console.log('error avatar') to console.log(err) , and now gives me Error: Unsupported MIME type: image/webp , all file are .png and i could find anything ;( – Envyus Jul 28 '21 at 19:43
  • Set display format to PNG, you should be good to go on that issue now... – Thunder Jul 29 '21 at 02:22
  • Now gives me 'TypeError: Cannot read property 'send' of undefined' Here its my full code "index,js only" https://ghostbin.com/paste/7H2tN – Envyus Jul 29 '21 at 13:53