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
- 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 OPLatest, bun v1.1.29.
trace:
Would this still work?
or does it need to me "name": "" ?
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 hoodIdk.
What is a better way?
The ESM way?
Dynamic import
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 moduleshttps://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
What would the import look like as I have a type error at default.
What's the error?
Property 'default' does not exist on type 'Promise<any>'.
Well, as i said, it's asynchronous, so you'll need to resolve it's promise.
await it
I have to do the same for my handlers as well?
Using the import?
Yes
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?
What does type has to do with this?
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.
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 ^
Well i want it type imported but i am getting
Cannot find name 'SlashCommand'.
even tho I have defined it.GitHub
Discord-Bot/src/types.d.ts at 7d9d0d9be6e5dfb6bba8989e25fa5ec42e74f...
TeaClient Main Discord Bot. Contribute to TeaClientMC/Discord-Bot development by creating an account on GitHub.
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 itWell would it still fuction how it is without it?
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 pointlessAlso the handlers need to be async execute right?
If I am not wrong async returns a promise.
If you are doing async stuff inside it, tes, but this is basic js
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.why does your execute method return a function...
I got it working dw.