Cant get bot to work when put bot related files to another folder in src

Hello i try to put my botfiles to src/bot/ but the bot wont work if i do this:
└───src
│ index.ts

├───bot
│ ├───lib
│ │ constants.ts
│ │ setup.ts
│ │ utils.ts
│ │
│ └───listeners
│ │ mentionPrefixOnly.ts
│ │ ready.ts
│ │
│ └───commands
│ ├───chatInputCommands
│ │ chatInputCommandDenied.ts
│ │ chatInputCommandSuccess.ts
│ │
│ ├───contextMenuCommands
│ │ contextMenuCommandDenied.ts
│ │ contextMenuCommandSuccess.ts
│ │
│ └───messageCommands
│ messageCommandDenied.ts
│ messageCommandSuccess.ts

└───shared
└───src
│ index.ts

├───bot
│ ├───lib
│ │ constants.ts
│ │ setup.ts
│ │ utils.ts
│ │
│ └───listeners
│ │ mentionPrefixOnly.ts
│ │ ready.ts
│ │
│ └───commands
│ ├───chatInputCommands
│ │ chatInputCommandDenied.ts
│ │ chatInputCommandSuccess.ts
│ │
│ ├───contextMenuCommands
│ │ contextMenuCommandDenied.ts
│ │ contextMenuCommandSuccess.ts
│ │
│ └───messageCommands
│ messageCommandDenied.ts
│ messageCommandSuccess.ts

└───shared
No description
Solution:
either drop the "bot" subfolder and set main to dist/index.js in package.json OR override the automatically resolved folder by setting baseUserDirectory in the client options
Jump to solution
19 Replies
f1fty
f1fty6mo ago
tsconfig.json
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"tsBuildInfoFile": "dist/.tsbuildinfo"
},
"include": ["src"]
}
{
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"],
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"tsBuildInfoFile": "dist/.tsbuildinfo"
},
"include": ["src"]
}
f1fty
f1fty6mo ago
No description
Favna
Favna6mo ago
Sapphire will look for folders called commands and listeners in the same directory that the main property is configured to be at in the package.json as per the top red block on our guide: https://sapphirejs.dev/docs/Guide/getting-started/getting-started-with-sapphire You will have likely set it to dist/index.js so you will either need dist/commands and such, or set a custom directory with baseUserDirectory in the client options. (make sure you dont set it to a directory in src if you do!)
Sapphire Framework
Getting started with Sapphire | Sapphire
To install Sapphire, you need to install both discord.js and
f1fty
f1fty6mo ago
so i cant run the bot in src/bot ?
Favna
Favna6mo ago
Node cannot run TS files directly so you will need to compile them first and as per your own config the files will be output to dist
f1fty
f1fty6mo ago
yeah i can compile it but it doesnt recognized src/bot/listeners/
No description
Favna
Favna6mo ago
because of what I said...
Solution
Favna
Favna6mo ago
either drop the "bot" subfolder and set main to dist/index.js in package.json OR override the automatically resolved folder by setting baseUserDirectory in the client options
f1fty
f1fty6mo ago
baseUserDirectory must be bot then?
Favna
Favna6mo ago
dist/bot
f1fty
f1fty6mo ago
Error when loading 'dist\bot\listeners\commands\messageCommands\messageCommandSuccess.js': Error: Cannot find module 'dist\bot\listeners\commands\messageCommands\messageCommandSuccess.js'
Error when loading 'dist\bot\listeners\commands\messageCommands\messageCommandSuccess.js': Error: Cannot find module 'dist\bot\listeners\commands\messageCommands\messageCommandSuccess.js'
Favna
Favna6mo ago
is there more to the error
f1fty
f1fty6mo ago
yes wait
Error when loading 'dist\bot\listeners\commands\chatInputCommands\chatInputCommandDenied.js': Error: Cannot find module 'dist\bot\listeners\commands\chatInputCommands\chatInputCommandDenied.js'
Require stack:
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\strategies\LoaderStrategy.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\index.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\framework\dist\cjs\lib\utils\application-commands\ApplicationCommandRegistries.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\framework\dist\cjs\index.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\dist\bot\lib\setup.js
- G:\Entwicklung - Fremd\hlx-ticketbot-api\dist\bot\index.js
- G:\Entwicklung - Fremd\hlx-ticketbot-api\dist\index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at _ListenerLoaderStrategy.preload (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\strategies\LoaderStrategy.cjs:60:17)
at _ListenerLoaderStrategy.load (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\strategies\LoaderStrategy.cjs:66:31)
at load.next (<anonymous>)
at _ListenerStore.loadPath (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\structures\Store.cjs:299:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async _ListenerStore.loadAll (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\structures\Store.cjs:211:24) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\pieces\\dist\\cjs\\lib\\strategies\\LoaderStrategy.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\pieces\\dist\\cjs\\index.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\framework\\dist\\cjs\\lib\\utils\\application-commands\\ApplicationCommandRegistries.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\framework\\dist\\cjs\\index.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\dist\\bot\\lib\\setup.js',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\dist\\bot\\index.js',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\dist\\index.js'
]
Error when loading 'dist\bot\listeners\commands\chatInputCommands\chatInputCommandDenied.js': Error: Cannot find module 'dist\bot\listeners\commands\chatInputCommands\chatInputCommandDenied.js'
Require stack:
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\strategies\LoaderStrategy.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\index.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\framework\dist\cjs\lib\utils\application-commands\ApplicationCommandRegistries.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\framework\dist\cjs\index.cjs
- G:\Entwicklung - Fremd\hlx-ticketbot-api\dist\bot\lib\setup.js
- G:\Entwicklung - Fremd\hlx-ticketbot-api\dist\bot\index.js
- G:\Entwicklung - Fremd\hlx-ticketbot-api\dist\index.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1143:15)
at Module._load (node:internal/modules/cjs/loader:984:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:179:18)
at _ListenerLoaderStrategy.preload (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\strategies\LoaderStrategy.cjs:60:17)
at _ListenerLoaderStrategy.load (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\strategies\LoaderStrategy.cjs:66:31)
at load.next (<anonymous>)
at _ListenerStore.loadPath (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\structures\Store.cjs:299:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async _ListenerStore.loadAll (G:\Entwicklung - Fremd\hlx-ticketbot-api\node_modules\@sapphire\pieces\dist\cjs\lib\structures\Store.cjs:211:24) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\pieces\\dist\\cjs\\lib\\strategies\\LoaderStrategy.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\pieces\\dist\\cjs\\index.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\framework\\dist\\cjs\\lib\\utils\\application-commands\\ApplicationCommandRegistries.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\node_modules\\@sapphire\\framework\\dist\\cjs\\index.cjs',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\dist\\bot\\lib\\setup.js',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\dist\\bot\\index.js',
'G:\\Entwicklung - Fremd\\hlx-ticketbot-api\\dist\\index.js'
]
other files also
f1fty
f1fty6mo ago
No description
Favna
Favna6mo ago
I honestly have no idea. Pinging @kyra 🩵🩷🤍🩷🩵 in here
Want results from more Discord servers?
Add your server