Subcommand in Direct Messages even with guildIds option

I have { guildIds: [this.container.config.guildId] } in my subcommand registry, but I still can see command in direct messages with that bot
No description
21 Replies
Favna
Favna3mo ago
Might just be client cache but if you want to be absolutely sure use the discordjs methods for managing application commands to check if it's there or not
TweenkySuwaru
TweenkySuwaruOP3mo ago
Okay so... I have like 5 bots, and some of them has some commands that registered globally. Tried to remove all applicationCommands for one of them just to see if it will solve the issue. But no, when I restarted bot command still was registering to global list even with specified guildId. I looked up at setup file that I call for registering plugins and found that: ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(RegisterBehavior.Overwrite). Changed to just Overwrite, but still commans remain in global list and even some old commands that no longer included in bot (they was literally deleted from files) are here, wtf :/ using ApplicationCommandRegistries.setDefaultGuildIds and RegisterBehavior.BulkOverwrite worked fine. Global commands were removed, and old commands that don't even exist too. But I have command for example /ticket that should be available globaly. I wonder why sapphire registers some commands to global list even with provided guildIds property on them Like why ApplicationCommandRegistries.setDefaultGuildIds worked, but
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder.setName(this.name).setDescription(this.description)
),
{
guildIds: [this.container.config.guildId],
}
}
public override registerApplicationCommands(registry: Command.Registry) {
registry.registerChatInputCommand((builder) =>
builder.setName(this.name).setDescription(this.description)
),
{
guildIds: [this.container.config.guildId],
}
}
this code dont I found out that commands have .setContexts() method. It worked! Commands are no longer visible in dms if I set it to Guild. But anyway, sapphire still register them as global commands, very weird why it's registering globally at all with provided guildIds I even tried to delete this commands using d.js and info from that doc about commands being stored and not removed after created. Anyway same result, they registreting to global list. I will try to reinstall node_modules, maybe that an issue with cache or something else at the deeper lvl... And if that will not solve the issue - i have 0 ideas why this could happening Will stick to that solution for now 👍 But it feels like that an very bad solution...
vladdy
vladdy2mo ago
uhm, theres no way for that code to not have made the cmd just on the guild.. can you get us a minimum repro sample pls in a repo
secre
secre2mo ago
Writing from my main acc. Currently working on creating repro sample. I read in #cant declare container items that you need to include some stuff in .npmrc config for sapphire to work properly when using pnpm. On my main repo I don't get those errors about packages not found when declaring stuff. But now when I'm creating sample I got one error. Could it be potential problem why commands registering weird? :hmmm: Done! Repo: https://github.com/shysecre/test-sample-sapphire 1. Clone. pnpm install in main directory. pnpm because I use workspaces by pnpm. I dont know if other package managers will work :Shruge: 2. Fill in dev config in config/dev.json with tokens & guild id 3. Maybe check out redis settings if they will overlap with yours. I use docker-compose 4. pnpm build, pnpm start:devmod Also I have a .tasks for vscode so you can easily start "watch" for all packages. Ctrl + Shift + P -> Run Tasks -> watch:all and then if restart is needed pnpm start:devmod I guess that's all :eeeh: Also I removed .setContexts for commands in yume-bot. And this commands still registering globally. setup function can be found in packages/common/src/util/setup.ts In packages folder I also have sapphire-utilities stuff where I register shared preconditions, listeners, utilities among all bots. I dont think that will somehow effect commands, but yeah
vladdy
vladdy2mo ago
What is the config module exactly I can't see it in pkg.jsons nor defined otherwise
secre
secre2mo ago
https://www.npmjs.com/package/config and its on 52 line of package.json "config": "^3.3.12",
vladdy
vladdy2mo ago
Can you print your config that's loaded and ensure the guild id is correctly there
secre
secre2mo ago
It's loading tokens so I guess guildId works too... But yeah sure, give me a sec
secre
secre2mo ago
secre
secre2mo ago
yea config loads correctly
No description
vladdy
vladdy2mo ago
Interesting And you're using bulkOverwrite correct?
secre
secre2mo ago
Yes. You can check that in this file
vladdy
vladdy2mo ago
what is that pnpm version, it does not exist at all your repro can't even start bc of config might be a local issue, not sure
2024-11-06 00:56:56 - ERROR - TypeError: Cannot read properties of undefined (reading 'economy')
2024-11-06 00:56:56 - ERROR - at main (/Users/vlad/Development/Sapphire/__REPROS__/test-sample-sapphire/apps/economy-bot/build/index.js:16:68)
2024-11-06 00:56:56 - ERROR - at Object.<anonymous> (/Users/vlad/Development/Sapphire/__REPROS__/test-sample-sapphire/apps/economy-bot/build/index.js:22:1)
2024-11-06 00:56:56 - ERROR - at Module._compile (node:internal/modules/cjs/loader:1546:14)
2024-11-06 00:56:56 - ERROR - at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
2024-11-06 00:56:56 - ERROR - at Module.load (node:internal/modules/cjs/loader:1317:32)
2024-11-06 00:56:56 - ERROR - at Module._load (node:internal/modules/cjs/loader:1127:12)
2024-11-06 00:56:56 - ERROR - at TracingChannel.traceSync (node:diagnostics_channel:315:14)
2024-11-06 00:56:56 - ERROR - at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
2024-11-06 00:56:56 - ERROR - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:166:5)
2024-11-06 00:56:56 - ERROR - at node:internal/main/run_main_module:30:49
2024-11-06 00:56:56 - ERROR - TypeError: Cannot read properties of undefined (reading 'economy')
2024-11-06 00:56:56 - ERROR - at main (/Users/vlad/Development/Sapphire/__REPROS__/test-sample-sapphire/apps/economy-bot/build/index.js:16:68)
2024-11-06 00:56:56 - ERROR - at Object.<anonymous> (/Users/vlad/Development/Sapphire/__REPROS__/test-sample-sapphire/apps/economy-bot/build/index.js:22:1)
2024-11-06 00:56:56 - ERROR - at Module._compile (node:internal/modules/cjs/loader:1546:14)
2024-11-06 00:56:56 - ERROR - at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
2024-11-06 00:56:56 - ERROR - at Module.load (node:internal/modules/cjs/loader:1317:32)
2024-11-06 00:56:56 - ERROR - at Module._load (node:internal/modules/cjs/loader:1127:12)
2024-11-06 00:56:56 - ERROR - at TracingChannel.traceSync (node:diagnostics_channel:315:14)
2024-11-06 00:56:56 - ERROR - at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
2024-11-06 00:56:56 - ERROR - at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:166:5)
2024-11-06 00:56:56 - ERROR - at node:internal/main/run_main_module:30:49
aha NODE_ENV=dev node ./apps/economy-bot/build/index.js this sees no cmds :CLk_Kekega: ok
secre
secre2mo ago
vladdy
vladdy2mo ago
NODE_ENV=dev NODE_CONFIG_DIR=../../config node ./build/index.js bleh ok CNR tho not with economy at least your event-bot has no guild ids bc of syntax errors baited by comma operator ticket doesn't have it at all same syntax issues in yume you could/should also use defaultGuildIds for this so you don't forget it
secre
secre2mo ago
it's kinda interesting because I created snippet for commands at the start and used it for all others. I wanna check if others commands have the same issue I can't because sometimes I need commands that users can use in dms too. As ticket command (i don't know why I even include it in repro sample, my bad)
vladdy
vladdy2mo ago
well, regardless, main issue is you have comma operator issues
secre
secre2mo ago
I see yes. And it also occurs in my snipper. I probably should fix that in all commands :||| I wonder why TS gives no error about this comma
vladdy
vladdy2mo ago
because its valid syntax and is used a lot in bundlers too when shrinking code eslint would've probably caught that tho
secre
secre2mo ago
probably will add lint to project, would be great in the distance to not make stupid mistakes like this :derp: thanks for help and your time I guess. Pretty awkward to ask someone to help and found out that issue was because of a single comma :WAHHHHHHHHHHHHH:
vladdy
vladdy2mo ago
yeahhh, been there done that dw
Want results from more Discord servers?
Add your server