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 toolkit2mo 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
eveeifyeveOP2mo 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
NyR2mo 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
eveeifyeveOP2mo ago
Idk. What is a better way? The ESM way?
NyR
NyR2mo ago
Dynamic import
d.js docs
d.js docs2mo 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
NyR2mo 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
eveeifyeveOP2mo ago
What would the import look like as I have a type error at default.
NyR
NyR2mo ago
What's the error?
eveeifyeve
eveeifyeveOP2mo ago
Property 'default' does not exist on type 'Promise<any>'.
NyR
NyR2mo 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
eveeifyeveOP2mo ago
I have to do the same for my handlers as well? Using the import?
NyR
NyR2mo ago
Yes
eveeifyeve
eveeifyeveOP2mo 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
NyR2mo ago
What does type has to do with this?
eveeifyeve
eveeifyeveOP2mo 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
NyR2mo 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
eveeifyeveOP2mo ago
Well i want it type imported but i am getting Cannot find name 'SlashCommand'. even tho I have defined it.
eveeifyeve
eveeifyeveOP2mo ago
NyR
NyR2mo 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
eveeifyeveOP2mo ago
Well would it still fuction how it is without it?
NyR
NyR2mo 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
eveeifyeveOP2mo ago
Also the handlers need to be async execute right? If I am not wrong async returns a promise.
treble/luna
treble/luna2mo ago
If you are doing async stuff inside it, tes, but this is basic js
eveeifyeve
eveeifyeveOP2mo 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
monbrey2mo ago
why does your execute method return a function...
eveeifyeve
eveeifyeveOP2mo ago
I got it working dw.
Want results from more Discord servers?
Add your server