My discord bot is only running on NodeJS v16 not v18

When I update my NodeJS to v18 my bot is not running on it…
when I install the previous update ( NodeJS v16 ) it runs perfectly.
How can I make it run on v18? what’s the problem?
the code:

const express = require("express");
const app = express();

app.listen(() => console.log(`Bot Is Ready`));

app.use('/ping', (req, res) => {
    res.send(new Date());
});

const Discord = require('discord.js');
const fs = require("fs");
const client = new Discord.Client({intents: 32767});
const { MessageAttachment } = require('discord.js');
const Canvas = require("canvas");
const { inviteTracker } = require("discord-inviter")

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



client.on('guildMemberAdd', async (member, inviter, invite) => {
    var x = member.guild.channels.cache.get("1020101321937911918")
    const background = await Canvas.loadImage("wallpaper.png");
    const canvas = Canvas.createCanvas(500, 357);
    const ctx = canvas.getContext('2d');
    ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
	///
	//
// Add an exclamation point here and below

let text = member.displayName;
if(text.length > 13) {
  text = text.slice(0, 13) + "...";
}

    ctx.font = 'bold 30px sans-serif';
    ctx.fillStyle = '#ffffff';
	ctx.textAlign = "center"
    ctx.fillText(text, 167, 300);
    ctx.beginPath();
    ctx.arc(165, 163, 105, 0, Math.PI * 2, false);
    ctx.closePath();
    ctx.clip();
    const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'png', size: 512 }));
    

    ctx.drawImage(avatar, 60.00, 58.00, 210.99999999999997, 210.99999999999997);

    const attachment = new Discord.MessageAttachment(canvas.toBuffer());
    await x.send({files: [attachment]})
    
});

tracker = new inviteTracker(client)

tracker.on("guildMemberAdd", async (member, inviter, invite) => {
    try {
        let sleep = async (ms) => await new Promise(r => setTimeout(r,ms));
            const ch = member.guild.channels.cache.get("1020101321937911918")
        await sleep(500)
            await ch.send({ content: `**Welcome To AsooL**  <@${member.user.id}>` })
    } catch (err) {
       console.log(err)
    }
})

client.login("token");

/*


*/

package.json:

{
  "name": "nodejs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/node": "^18.0.6",
    "canvas": "^2.11.2",
    "discord-inviter": "^0.9.1",
    "discord.js": "^13.10.3",
    "express": "^4.18.1",
    "node-fetch": "^3.2.6"
  }
}

why no one is replying?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.