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....
Solution
F
Favna12d 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!
M
Malik12d 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
F
Favna12d 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.
O
Oreo ™12d 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
M
Malik12d 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.
B
BigBrainAFK11d 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
More Posts
Stricter type checking for string command choicesHi, was wondering if this is possible. In this example I am doing a command that can change my bot'WIll this work?```ts public override registerApplicationCommands(registry: Command.Registry) { registryAccessing data in subcommandsI was wondering if there any way of accessing all the data passed in the subcommand without having mIssue with inviteCreate eventHello. I have an issue with the `inviteCreate` event where it won't fire unless the invite created hrole not being givenlogs saying they were removed, but they weren'tButton erroranybody knows why this is happening? So I have a ticketing system that just stopped working now, forShould i acquire every command or only onceHello I just got interest to Sapphire and when i was reading advanced doc for registering commands ono error event on subcommand preconditionwhat event fires when a Subcommand's precondition (on a subcmd, not the whole class) fails? i'm not apply precondition to only one Subcommand?I was wondering if there's a decorator or something, or if I need to run the logic manually.Ready event does not run```ts import { Listener } from "@sapphire/framework"; import { Client } from "discord.js"; export cSlash Command Error`node:events:492 throw er; // Unhandled 'error' event ^ TypeError: interaction.isChatInError when clicking buttonerror: https://srcb.in/dIL4feMtz6 code: https://srcb.in/MGmSNTYXw6 I tried using Message Component Prevent commands from being ran on DMs and prevent bots from using commands by defaultdid Sapphire recently add this behavior stated in the title? I recently removed Preconditions that pButton doing nothing```const button = new ButtonBuilder() .setCustomId("COB") .setLabel("Custom InteractionOptionResolver pleasing TypeScriptI have an HTTP interactions app that utilizes `@discordjs/core/http-only`. Currently, I have my own JavascriptAlright guys, quick question if i am new to javascript (i want to learn typescript by the way.) and Any way to add a sort of "middleware" to all listenersIs there any way to have something like a middleware or precondition for all events? I want to delayAre my slashcommands guild based or global?When I use `registerApplicationCommands` (like shown in the picture) does that command get registereTwo Commands In One Filewhen i export chat input command and user context menu command in one file it reads the first exportQuestion regarding client.login()A bit of a curiosity question, I noticed that you can use `await client.login();` without providing