Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

397
Views
How to read Class Objects / Functions when passed as a param?

I'm current working with Discord's Gateway and sockets to create something similar to discord.js and to make it easier for a new user to use the package i'm making i would like them to view the Message class objects and functions when passed as a param. I have been unsuccessful in all of my attempts at this.

Example from Discord.js:

Discord.js's Example

Example from My Package:

My Example

My .on() Code:

/**
 * client.on() [ when received certain operation from discord's gateway ]
 * @param {OPERATION} operation 
 * @param {FUNCTION} func 
 */
on(operation, func) {

    ws.on('message', (data) => {
        let payload = JSON.parse(data)
        const {t, event, op, d} = payload

        // OPERATION => operation
        operation = operation.toLowerCase();

        // if op => message
        switch(operation) {
            case "message": {
                switch(t) {
                    case "MESSAGE_CREATE":
                        // message build
                        let message = new Message().init(d, this.token)
                        return func(message)
                        //          ^^^^^^^ this is where message is passed
                    }
            }
        }
        
        })

}

My Message.init() Code:

init(d, token) {

    this.content = d.content
    this.channel = {
        id: d.channel_id,
        send: (content) => {
            sendMessage(d.channel_id, token, content)
        }
    }
    this.author = {
        bot: d.author.bot ? d.author.bot : false,
        username: d.author.username,
        tag: `${d.author.username}#${d.author.discriminator}`,
        identifier: d.author.discriminator,
        id: d.author.id,
        avatar: `https://cdn.discordapp.com/avatars/${d.author.id}/${d.author.avatar}.gif` // avatar image
    }
    this.guild = {
        id: d.guild_id
    }
    this.timestamp = d.timestamp

    return this

}

I've looked something like this up and couldn't find anything specific to what I'm looking for.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to tell jsdoc what arguments your function accept. While FUNCTION works generically you need to be more specific:

/**
 * client.on() [ when received certain operation from discord's gateway ]
 * @param {OPERATION} operation 
 * @param {(message:Message) => void} func 
 */

This says that the second argument is a function that returns nothing (void) and has a Message object as its argument. Presumably then you will have a Message class/constructor somewhere in your project.

about 4 years ago · Juan Pablo Isaza Report

0

Document your code using jsdoc. you'll probably want to read more about it at https://jsdoc.app/

Once you'll have that vscode (and other supported IDEs) will do the rest of the "magic"

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!