Subcommands Not Working
Hello, I am trying to make my subcommands "tidy" by using separate files, but the functions aren't even running.
server.command.ts
Solution:Jump to solution
@Enrique I looked into the issue and I can run subcommands just fine. I created a PR with the changes I made https://github.com/b1nzeex/dvs-discord-bot-v2/pull/1
The notable ones are:
- Reinstalling dependencies, part of updating to yarn v4
- Setting up the initial Prisma migration so the schema is created. You connect the database, so you need to make sure Prisma can actually interact with it. Without this the application should just crash at init anyway...
70 Replies
_server.add.subcommand.ts
To clarify, my
console.log("test")
doesn't execute
Still experiencing this issue :pepeFeelsBadMan:
@HelpersThe parent and subcommands get properly registered on the discord API? I suspect not because I don't see a return statement from the builder. Note the difference between
command => command.stuff
and command => { command.stuff }
in JavaScript arrow functions. The latter would have to be command => { return command.stuff }
or command => { command.stuff; return command }
What is the parsed name of the parent command? Seeing as you dynamically compute it.
FYI category is automatically computed by sapphire based on directory structure. For example src/commands/general/other/my command.ts
has a full category of ['general', 'other']
(you shouldnt neeeed to return but i dont remember)
The commands are registering properly, they appear in my slash command list
But didn't know the category part, thank you for the useful information there
You 100% do, we've had people face that issue before.
You're using bulk overwrite mode? Sure that what you see isn't old registered data? Checking because you're not using idHints
i thought i fixed that
Well I may be wrong but it's easily checked. Ofc I can't from where I am but be my guest.
im using bulkOverwrite, yeah
and when I add
return
to the registry.registerChatInputCommand(), I get this error:
not there
in the registerChatInputCommand call
no error, but command still not running
for reference btw, I'm not returning in my ping command either and that works
hmmm
This is where vladdy and I meant btw. That should be
return command
thought so, thats where i tried just now
what's the result of
parse(__filename).name.split(".")[0]
?
And your bot has those permissions you're requiring?
Also you can enable the error listeners to see logging hold onyeah the name can be sus
Just did this in my ping command, it returns "ping" - so same should work for my server command
and yeah, it has admin perms
loadSubcommandErrorListeners
to true in client options
And set logger.loglevel to LogLevel.Debug
Excuse any typos
I'm on mobilemmm it might not tho, unless the ping cmd has the same name structure
But you're using TS so intellisense can correct for me
You can add a console.log above the class definition in the same file. It'll get logged when the bot starts when the file is loaded.
Adding to that
no errors
You're not using bulk overwrite.. those logs are not that.
even then it shows the name is correct
just did that, it logged "server"
oh shit, im using "Overwrite" my bad
To enable bulk overwrite: https://sapphirejs.dev/docs/Guide/commands/application-commands/application-command-registry/advanced/setting-global-behavior-when-not-identical
Sapphire Framework
Configuring the global behavior when commands are not identical | S...
Configuring the global behavior is easy! You just need to import the
doesnt matter
It's a safety sanity check really because for all we know id/name comparison is borked (wouldn't be the first time lol)
we also use names
i normally use bulk overwrite, must have overlooked it, but new logs:
Right and I guess it still doesn't work?
same ids
so as i said
thats not it
yeah still just "Application Didnt Respond" with 0 error
Did you enable this option? Any logging when you use the command?
i know sapphire doesn't typically "support" subcommands in separate files, but the console.log("test") should fire at least right?
and yeah i enabled that
yes to your question
which reminds me i found an oversight on our part, we run code only on constructor not onLoad
but unrelated to this
just to make sure im correct here too, this is my constructor for the SapphireClient
looks fine
Can you implement listeners for each of these events for chat input and see what that gives? https://github.com/sapphiredev/plugins/blob/main/packages/subcommands/src/lib/types/Events.ts
You can just log dump a test or something in the listener. We just need to know if they get emitted at all for now.
GitHub
plugins/packages/subcommands/src/lib/types/Events.ts at main · sapp...
Plugins for the Sapphire Framework. Contribute to sapphiredev/plugins development by creating an account on GitHub.
sure, gimme a few mins
That's lines 7-10 and line 18 btw
Oh other than the test also log the name/event of the listener ofc. We need to be able to tell them apart
also if this is an open source project, feel free to link us, we can take a look then too
I need to go now. Hopefully vladdy can help you further otherwise I'm back in like 4ish hours
alright, think I did the listeners correctly
but still not getting an output
chatInputSubcommandDenied.listener.ts
chatInputSubcommandRun.listener.ts
chatInputSubcommandSuccess.listener.ts
chatInputSubcommandError.listener.ts
subcommandMappingIsMissingChatInputCommandHandler.listener.ts
The names are invalid this way. The name has to be the exact event name OR you need to specify the event as a separate config property. In your case that's what you want to do. So add
event: SubcommandPluginEvents. ChatInputSubcommandDenied
and so on.
(this is the case for all listeners, subcommands or otherwise)
Oh and also enabled is true by default
Oh wait the way you parse the name it matches doesn't it.
It's so confusing the way you name files lolno thats not gonna work
the snippets I provided just now are wrong, I forgot to use
parse
etc, but I have hardcoded it now
still nothingdidddd you calll registerrr in your entrypoint?
yes
index.ts
has there been an update at all to the subcommands plugin that may have broke anything? shall I try a previous version?
unrelated but dotenv is built-in the stable version of node, about 20>
you should be using latest version if you're on latest sapphire
fair, thank you for informing me
yeah, all of these are fresh installs, the day I made this thread
is this open source?
not rn, but I can make a repo quick if you want
uhh, it might help yea
GitHub
GitHub - b1nzeex/dvs-discord-bot-v2
Contribute to b1nzeex/dvs-discord-bot-v2 development by creating an account on GitHub.
FYI you're right but that only extends to dotenv, not dotenv-expand or some of the more advanced options of dotenv.
I’m aware
This one won't be called OwnerOnly when loaded at runtime but ownerOnly.precondition @Enrique https://github.com/b1nzeex/dvs-discord-bot-v2/blob/main/src/preconditions/ownerOnly.precondition.ts
And can you validate what vladdy said about __filename?
GitHub
dvs-discord-bot-v2/src/preconditions/ownerOnly.precondition.ts at m...
Contribute to b1nzeex/dvs-discord-bot-v2 development by creating an account on GitHub.
The __filename stuff has been logging correctly
But in the listeners I did hardcode for debugging purposes
I'm stumped honestly. I guess I'll have to run the bot myself. Alternatively if you want you can use a vscode debugger session and set breakpoints in your node_modules in the JS files of sapphire to see where the execution goes. I'll be doing the same.
I have only ever used the debugger like once xD you'd probably find better results doing it, i dont really know what im doing with the debugger
Created a new public reminder with ID
xYiwjwtIwWc_qyFGsHUHQ
, I will send you a message on <t:1711206286:F>. Click on the button to (un)subscribe to the reminder.debug this issue
xYiwjwtIwWc_qyFGsHUHQ
I won't have time before then
Solution
@Enrique I looked into the issue and I can run subcommands just fine. I created a PR with the changes I made https://github.com/b1nzeex/dvs-discord-bot-v2/pull/1
The notable ones are:
- Reinstalling dependencies, part of updating to yarn v4
- Setting up the initial Prisma migration so the schema is created. You connect the database, so you need to make sure Prisma can actually interact with it. Without this the application should just crash at init anyway
- Adding that
return
we mentioned before in server.command.ts
- Specifying that the ownerOnly.precondition.ts
should have a name of OwnerOnly
to match line 17 in server.command.ts
And ofc I also added my own local .env
file with my token, an owner ID and a database url (DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres?schema=public
)
https://cdn.discordapp.com/attachments/838895947052089366/1217946610496045169/ishare-1710451491.PNG?ex=6605e02c&is=65f36b2c&hm=1a193ae6611761ad54472e1c5cff2078ff2af4b0d945aa45a26e15725a9f85cf&@Enrique
thank you, it was the precondition that was failing me 😫 thank you for the other noticed changes though too!
how come the file name HAS to be that?
On <t:1710443086>, @Favna and @Enrique asked me to remind you of this:
debug this issue
Ohwell :kekw: