discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.2k stars 3.96k forks source link

Working Discord.js with pkg application bundler #5543

Closed MateuszPrasal closed 3 years ago

MateuszPrasal commented 3 years ago

Hello ! :)

I'm creating bot and I'd like to bundle whole app to single executable file - for this i'm using PKG library. Everything is working, but there is one problem because i'm not receiving messages from Discord. I think the problem is in PKG configuration (maybe there is configuration which allows to listening specific ports?) because if I start my app from command line like npm run start and nodejs server is ready, every message has been provided and is visible in my console.

Maybe anyone has same problem ?

My code is almost exactly the same like in documentation

main.ts

const Discord = new DiscordService;

Discord.getClient().on('ready', () => {
        Logger.info('Ready for new messages')
    })
    Discord.getClient().on('message', (message: Message) => {
        Logger.info(message.content.toString());
    });

    Discord.login();

DiscordService.ts

import Discord, { Client } from 'discord.js';

import { ConfigType, getConfig } from './Config';
import Logger from './Logger';

export default class DiscordService {
    client: Client;
    config: ConfigType;

    constructor() {
        this.client = new Discord.Client();
        this.config = getConfig();
    }

    login(): void {
        this.client.login(this.config.discordToken)
            .then(() => {
                Logger.info('Login in discord')
            })
    }

    getClient(): Client {
        return this.client
    }
}

Thanks for help ! :)

monbrey commented 3 years ago

The issue tracker is only for bug reports and enhancement suggestions. If you have a question, please ask it in the Discord server instead of opening an issue – you will get redirected there anyway.