TS Bot Handlers not running with correct envs

can anyone figure out why the handlers in this bot is not working? I have provided correct envs. https://github.com/TeaClientMC/Discord-Bot/
GitHub
GitHub - TeaClientMC/Discord-Bot: TeaClient Main Discord Bot
TeaClient Main Discord Bot. Contribute to TeaClientMC/Discord-Bot development by creating an account on GitHub.
27 Replies
d.js toolkit
d.js toolkit2d ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
eveeifyeve
eveeifyeveOP2d ago
Latest, bun v1.1.29. trace:
false
Can't load the handler command.ts.
false
Can't load the handler event.ts.
Loaded 0 handlers.
false
Can't load the handler command.ts.
false
Can't load the handler event.ts.
Loaded 0 handlers.
Module {
__esModule: true,
default: {
name: "EventHandlers",
execute: [Function: execute],
},
}
Module {
__esModule: true,
default: {
name: "EventHandlers",
execute: [Function: execute],
},
}
Would this still work? or does it need to me "name": "" ?
NyR
NyR2d ago
That's the same thing, but as you can see, that's the default export and loading dynamically, you'll have to access the default property to get those, So const handler: ... = require(filepath).default I'm also confused, I see you using esm, but you are using require there, that should error, unless this is a bun feature which idk or some transforming is happening under the hood
eveeifyeve
eveeifyeveOP2d ago
Idk. What is a better way? The ESM way?
NyR
NyR2d ago
Dynamic import
d.js docs
d.js docs2d ago
:mdn: import() The import() syntax, commonly called dynamic import, is a function-like expression that allows loading an ECMAScript module asynchronously and dynamically into a potentially non-module environment.
NyR
NyR2d ago
It's asynchronous, so you'll have to make your function async
In Bun's JavaScript runtime, require can be used by both ES Modules and CommonJS modules
https://bun.sh/docs/runtime/modules#module-systems So i suppose you can keep it as is, as long as you are planning to use Bun only
eveeifyeve
eveeifyeveOP2d ago
What would the import look like as I have a type error at default.
NyR
NyR2d ago
What's the error?
eveeifyeve
eveeifyeveOP2d ago
Property 'default' does not exist on type 'Promise<any>'.
NyR
NyR2d ago
Well, as i said, it's asynchronous, so you'll need to resolve it's promise. await it
const { default: handler } = (await import(filepath)) as { default: Handler }
const { default: handler } = (await import(filepath)) as { default: Handler }
eveeifyeve
eveeifyeveOP2d ago
I have to do the same for my handlers as well? Using the import?
NyR
NyR2d ago
Yes
eveeifyeve
eveeifyeveOP2d ago
Cause I have a type called SlashCommand under types.d.ts, do I just call that for commands? Or do I need to make a new type?
NyR
NyR2d ago
What does type has to do with this?
eveeifyeve
eveeifyeveOP2d ago
This type is for the slashCommands. . And it's needs to be used in the command handler. I don't know if it's possible without creating a new type.
NyR
NyR2d ago
I'm still not understanding, what does type has to do with importing dynamically, if you want to type the imported stuff, just do how i showed here ^
eveeifyeve
eveeifyeveOP2d ago
Well i want it type imported but i am getting Cannot find name 'SlashCommand'. even tho I have defined it.
eveeifyeve
eveeifyeveOP2d ago
NyR
NyR2d ago
Why is your SlashCommand extending ChatInputApplicationCommandData, i see no corelation there? You can just have it as a sole interface. And about your error, make sure you import the type where you are using it
eveeifyeve
eveeifyeveOP2d ago
Well would it still fuction how it is without it?
NyR
NyR2d ago
Yes, because I don't see you using any of the properties of the said type, you already have the command data in your data property, extending it seems pointless
eveeifyeve
eveeifyeveOP2d ago
Also the handlers need to be async execute right? If I am not wrong async returns a promise.
treble/luna
treble/luna2d ago
If you are doing async stuff inside it, tes, but this is basic js
eveeifyeve
eveeifyeveOP2d ago
export declare type Handler = {
name: string;
execute: Promise<function>;
};
export declare type Handler = {
name: string;
execute: Promise<function>;
};
So would this be correct? Type '(client: Client<true>) => Promise<void>' is not assignable to type 'Promise<function>'. That's what I got for command handler.
monbrey
monbrey2d ago
why does your execute method return a function...
eveeifyeve
eveeifyeveOP2d ago
I got it working dw.
Want results from more Discord servers?
Add your server