NetCord icon indicating copy to clipboard operation
NetCord copied to clipboard

Guidance on registering slash commands per guild with NetCord.Hosting.Services

Open sillock1 opened this issue 4 months ago • 1 comments

Description

This change has broken the ability to register slash commands using the SlashCommandAttribute on a per guild basis. I currently follow this guidance in your docs alongside custom bases for registering http interaction commands using annotations. What is the preferred way to register http interactions on a per guild basis to allow for "local" testing?

sillock1 avatar Aug 19 '25 16:08 sillock1

Hi, I think we might think of explaining how to register app commands to guilds (cc @Mewyk). For now you can see this example:

var services = host.Services;

var service = services.GetRequiredService<ApplicationCommandService<HttpApplicationCommandContext>>();

var client = services.GetRequiredService<RestClient>();

var properties = await Task.WhenAll(service.GetCommands().Where(c => c.Name is not ("some" or "filter" or "if" or "needed")).Select(c => c.GetRawValueAsync().AsTask()));

ulong guildId = 856183259972763669;

await client.BulkOverwriteGuildApplicationCommandsAsync(((IEntityToken)client.Token!).Id, guildId, properties);

Also you will probably want to set AutoRegisterCommands to false in the configuration.

That said, I think local testing should be done on a separate Discord application (bot).

KubaZ2 avatar Aug 19 '25 17:08 KubaZ2