Listeners and Index.js

Hello, I basically made a Giveaway System, but I have a code that needs to be in index.js and 1 that needs to be as event, but right now I am clueless as where to put the index.js to put it into perspective of normal discord.js framework, 1 code ness to be in the inde.js and the other in the events folder but I don't know where to put these code using the sapphire framework. When I put the code that's supposed to be in my index.js file, i get this error:
/home/container/src/index.js:22
client.giveawayManager = new GiveawaysManager(client, {
^
TypeError: GiveawaysManager is not a constructor
at Object.<anonymous> (/home/container/src/index.js:22:26)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
Node.js v20.12.0
/home/container/src/index.js:22
client.giveawayManager = new GiveawaysManager(client, {
^
TypeError: GiveawaysManager is not a constructor
at Object.<anonymous> (/home/container/src/index.js:22:26)
at Module._compile (node:internal/modules/cjs/loader:1369:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
at Module.load (node:internal/modules/cjs/loader:1206:32)
at Module._load (node:internal/modules/cjs/loader:1022:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
Node.js v20.12.0
The code that's supposed to go into index.js: https://sourceb.in/ANt8LGRFiM The code that's supposed to go into the events folder aka listener: https://sourceb.in/GD3Cbxbg5y Here is my current index.js and listener code with the giveaway code included:
Index.js - https://sourceb.in/9NXZs3iBfO Event - https://sourceb.in/bODqOfaqBX
Solution:
I can already tell that your event code is invalid btw. You cannot module.exports inside a run method. Nor would you even want to. Also sapphire already implements messageRun for handling commands, that's the whole point of using sapphire. Anyway I have no idea about your problem but it's not sapphire related. The error is saying that Giveaways manager is not a constructable class. Why that is, I don't know. Sidenote that giveaway bot exists and no offense but realistically no one is gonna use your bot over it, so unless you're just code practising, don't expect another giveaway bot to grow much. You're very unlikely to have a killer niche feature that giveaway bot doesn't cover. This is the problem will all discord bots, if you don't touch a niche yours won't grow much....
Discord GiveawayBot
GiveawayBot - Discord Giveaway Bot
Hold giveaways on your Discord server quickly and easily!
Jump to solution
6 Replies
Solution
Favna
Favna8mo ago
I can already tell that your event code is invalid btw. You cannot module.exports inside a run method. Nor would you even want to. Also sapphire already implements messageRun for handling commands, that's the whole point of using sapphire. Anyway I have no idea about your problem but it's not sapphire related. The error is saying that Giveaways manager is not a constructable class. Why that is, I don't know. Sidenote that giveaway bot exists and no offense but realistically no one is gonna use your bot over it, so unless you're just code practising, don't expect another giveaway bot to grow much. You're very unlikely to have a killer niche feature that giveaway bot doesn't cover. This is the problem will all discord bots, if you don't touch a niche yours won't grow much.
Discord GiveawayBot
GiveawayBot - Discord Giveaway Bot
Hold giveaways on your Discord server quickly and easily!
Wxrning
WxrningOP8mo ago
My niche is a rpg system and the rest are just for multipurpose Also, hooi hoe gaat het ik ging jou description gwn aankijken en zag dat je van nederland bent en nederlands kan spreken
Favna
Favna8mo ago
Can you dump the whole code base on GitHub? I'm a bit stumped on the error tbh. That's true but I try to keep it at English online because it doesn't alienate other readers. I also prefer it for coding talk anyway. Anyway I'm fine.
Oreo ™
Oreo ™8mo ago
Hey Malik, idk why youre exporting a class everytime a message is created in your event, but i think its probably because youre are importing the class from const GiveawaysManager = require("./events/giveaway") which is a file where you arent exporting it in (atleast validly). You should really just make a structures folder in your lib directory and add your helper classes in there, and you can add the code to instantiate the class in a ready listener instead of in index.js
Wxrning
WxrningOP8mo ago
I changed that path to the correct one, it still didn't work Also, I appreciate you both for trying to help but I have given up on the Giveaway System as I took @fanny's advise on focusing more on my bot's niche.
BigBrainAFK
BigBrainAFK8mo ago
unrelated to the issue but it also means everyone else with the same issue can understand what the problem was if its in a "universal language"
Want results from more Discord servers?
Add your server