Ask coding questions

← Back to all posts
project not loading because of promise pending
JasonCark (1)

for some reason when i try booting my discord bot it says "Promise { pending } when i dont have a promise or anything..

heres my index.js:

let fs = require("fs");
const http = require("http");
const express = require("express");
const app = express();
var server = http.createServer(app);
const Discord = require("discord.js");
const config = JSON.parse(fs.readFileSync("./config.json"));

const { registerFont } = require('canvas');
registerFont('./vera.ttf', { family: 'sans-serif' });

var bodyParser = require("body-parser");
app.use(bodyParser.json({ limit: "1gb" }));
app.use(bodyParser.urlencoded({ limit: "1gb", extended: true }));

const applyText = (canvas, text) => {
	const ctx = canvas.getContext('2d');
	let fontSize = 70;

	do {
		ctx.font = `${fontSize -= 10}px sans-serif`;
	} while (ctx.measureText(text).width > canvas.width - 300);

	return ctx.font;
};

app.get("/", (request, response) => {
  console.log("Ping Received");
  response.send("hi")
});

const listener = app.listen(process.env.PORT, function() {
  console.log(`Your app is listening on port ` + listener.address().port);
});

const { CommandoClient } = require("discord.js-commando");
const { Structures } = require("discord.js");
const { MessageEmbed } = require("discord.js");
const path = require("path");

const client = new CommandoClient({
  commandPrefix: config.prefix,
  owner: "721787608828477572" // change this to your Discord user ID
});

client.registry.registerDefaultTypes()
client.registry.registerGroups([
  ["member", "Member Commands"]
])
client.registry.registerDefaultGroups()
client.registry.registerDefaultCommands({
  help: false,
  ping: false,
  prefix: false,
  commandState: false,
  unknownCommand: false
})
client.registry.registerCommandsIn(path.join(__dirname, "commands"));

client.on("ready", () => {
  console.log("Up!")
});

client.on("message", function(message) {
  if(message.content.toLowerCase() == config.prefix+"emitjoin"){
    client.emit("guildMemberAdd", message.member)
  }
});

client.on("guildMemberAdd", async member => {
  const channellol = client.channels.cache.get("750789957077041233");
  if (channellol) {
    const Canvas = require("canvas")
    const canvas = Canvas.createCanvas(700, 250);
    const ctx = canvas.getContext('2d');
    const background = await Canvas.loadImage('./wallpaper.jpg');
    ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
    ctx.strokeStyle = '#74037b';
    ctx.strokeRect(0, 0, canvas.width, canvas.height);
    ctx.font = '28px sans-serif';
    ctx.fillStyle = '#ffffff';
    ctx.fillText('Welcome to the server,', canvas.width / 2.5, canvas.height / 3.5);
    ctx.font = applyText(canvas, `${member.displayName}!`);
    ctx.fillStyle = '#ffffff';
    ctx.fillText(`${member.displayName}!`, canvas.width / 2.5, canvas.height / 1.8);
    ctx.beginPath();
    ctx.arc(125, 125, 100, 0, Math.PI * 2, true);
    ctx.closePath();
    ctx.clip();
    const avatar = await Canvas.loadImage(member.user.displayAvatarURL({ format: 'jpg' }));
    ctx.drawImage(avatar, 25, 25, 200, 200);
    const attachment = new Discord.MessageAttachment(canvas.toBuffer(), 'welcome-image.png');
    channellol.send(`Hey! ${member.toString()}, Welcome To **Veratus**!`, attachment);
  }
});

client.on("guildMemberRemove", async member => {
  const channellol = client.channels.cache.get("750789957077041233");
  if (channellol) {
    channellol.send(`**${member.user.username}#${member.user.discriminator}** Left 😢`);
  }
});

var moe = {
  gc: function() {
    return client;
  }
};

for (var key in moe) {
  module.exports[key] = moe[key];
}

client.login(config.token);```
Comments
hotnewtop
Coder100 (18208)

It returns a promise, it will take time to fulfill the promise.
client.login is a promise if you forgot ;)

JBloves27 (1887)

oh, i don't know node.js xD @Coder100

JasonCark (1)

@Coder100 do i add ".then" and ".catch"? because on other hosting websites that doesnt return a promise

(it also isnt documented in the discordjs docs)

Coder100 (18208)

nope, this is repl.it they for some reason print out the return value of the last statement, if you add console.log("hi") you see the promise is gone @JasonCark

JBloves27 (1887)

Like one other people have person said, This happens sometimes, idk why, but yeah. So try reloading, it might help. :)

JasonCark (1)

@JBYT27 doesnt work i tried it multiple times.

JBloves27 (1887)

oh. hmmm, maybe there's an error with the code? @JasonCark

RYANTADIPARTHI (6018)

You might want to refresh. It happens. Just refresh and run it again.

Coder100 (18208)

doesn't help if that's what the code does silly @RYANTADIPARTHI