Best Approach on separating Commands from their "run" file to a separate Folder

For context, I am super new to discordjs and this framework so apologizes if this question sounds odd. I really dislike the approach that all examples in the example repository and docs are giving of having the command definition (if you call it like this) and the execution code of the command in the same file. What is the best way to separate them both? Or is it even possible?
Solution:
```ts import { myRunFunction } from '../lib/commands/my-command'; import { Command } from '@sapphire/framework'; export class MyCommand extends Command {...
Jump to solution
6 Replies
Solution
Favna
Favna2y ago
import { myRunFunction } from '../lib/commands/my-command';
import { Command } from '@sapphire/framework';

export class MyCommand extends Command {
public override async chatInputRun(interaction: Command.ChatInputInteraction) {
return myRunFunction(interaction);
}
}
import { myRunFunction } from '../lib/commands/my-command';
import { Command } from '@sapphire/framework';

export class MyCommand extends Command {
public override async chatInputRun(interaction: Command.ChatInputInteraction) {
return myRunFunction(interaction);
}
}
Other than that, it's not possible. Sapphire aims to be Object Oriented which means that code is encapsulated and highly coupled to the origin object, the command class. It sounds like you're rather looking for something following a more FP style which Sapphire doesn't offer. In fact I'd argue that modern JS in general, while allowing FP, isn't the best language for actual FP because there is a large focus on classes.
chillihero
chilliheroOP2y ago
I see, what does FP stand for?
Favna
Favna2y ago
functional programming
Favna
Favna2y ago
it's the total opposite of object oriented
chillihero
chilliheroOP2y ago
ahh yes, I see. Thank you
Favna
Favna2y ago
OOP combines data and its associated behavior into an object. This helps software programmers to easier understand how the program works, although the code is much longer than in FP. FP, on the other hand, clearly distinguishes data and behavior, keeping them separately.
source: https://scand.com/company/blog/functional-programming-vs-oop/#:~:text=OOP%20combines%20data%20and%20its,and%20behavior,%20keeping%20them%20separately. that pretty much describes what you were asking
Want results from more Discord servers?
Add your server