discordjs / discord.js

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

Structures #5890

Closed xhyrom closed 3 years ago

xhyrom commented 3 years ago

Please describe the problem you are having in as much detail as possible:

Include a reproducible code sample here, if possible:

guild.js

const { Structures } = require("discord.js")

module.exports = Structures.extend('Guild', Guild => {
    /**
     * The GuildStructure structure
     * @class
    */

    class GCommandsGuild extends Guild {
        constructor(...args) {
            super(...args)
        }

        /**
         * Method to getCommandPrefix
         * @returns {Promise}
        */
        async getCommandPrefix() {
            return this.client.dispatcher.getGuildPrefix(this.id);
        }

        /**
         * Method to setCommandPrefix
         * @returns {Boolean}
        */
        async setCommandPrefix(prefix) {
            this.client.dispatcher.setGuildPrefix(prefix, this.id);
            this.client.emit('commandPrefixChange', this, this._commandPrefix);
        }
    }

    return GCommandsGuild;
})

index.js

const Discord = require("discord.js");
require("./slash cmd/src/structures/guild")
const client = new Discord.Client({intents: ["GUILDS"]});

Further details:

Relevant client options:

My structure extend doesnt working in djs v13 | v12 works I have it defined before new Client() + i have GUILDS intents in new Client()

VoltrexKeyva commented 3 years ago

The description of your issue is not very informative, do you get any errors? What's the expected result? What's the unexpected result? Please elaborate on your issue.

xhyrom commented 3 years ago

in djs v12 .guild return GCommandsGuild and in djs v13 its return Guild

xhyrom commented 3 years ago

As long as I put the structure in the index and don't use require() it works.

SpaceEEC commented 3 years ago

Can you create a minimal reproducible example, as I am unable to reproduce this?

xhyrom commented 3 years ago

okay

xhyrom commented 3 years ago

Reproduce

When I tried in djs v13 not to use require("./slash cmd/src/structures/guild") and put that structure directly in index.js after the defined discord.js it worked fine.

My structure code is:

const { Structures } = require("discord.js")

module.exports = Structures.extend('Guild', Guild => {
    /**
     * The GuildStructure structure
     * @class
    */

    class GCommandsGuild extends Guild {
        constructor(...args) {
            super(...args)
        }

        /**
         * getCommandPrefix
         * @returns {Promise}
        */
        async getCommandPrefix() {
        return this.client.dispatcher.getGuildPrefix(this.id);
        }

        /**
         * setCommandPrefix
         * @returns {Boolean}
        */
    async setCommandPrefix(prefix) {
        this.client.dispatcher.setGuildPrefix(prefix, this.id);
        this.client.emit('commandPrefixChange', this, this._commandPrefix);
    }
    }

    return GCommandsGuild;
})

and in index.js I have:

const Discord = require("discord.js");
require("./slash cmd/src/structures/guild")
const client = new Discord.Client({ intents: ["GUILDS"]});
SpaceEEC commented 3 years ago

This is working fine for me on 13.0.0-dev.c850ae10270076c4b2e10b130dd8f88eed4ed201.

xhyrom commented 3 years ago

I just downloaded discord.js v13 via npm i discordjs/discord.js and it throws me this error. Multiple people have complained to me about this in my npm plugin gcommands.

Will you be so good as to try and test it on gcommands while you have the time?

DTrombett commented 3 years ago

I think you should use npm i discord.js@dev to install the master branch correctly. However I don't know if this is the problem...

xhyrom commented 3 years ago

Okay i go try

xhyrom commented 3 years ago

Thx, it works 😄