Registering commands in the GuildAvailable event doesn't seem to work #1632
-
I'm attempting to register commands in the I'm using the IReadOnlyDictionary<int, SlashCommandsExtension> slashCommands
= await DiscordClient.UseSlashCommandsAsync(SlashCommandsConfiguration);
slashCommands.RegisterCommands<TestSlashCommandModule>(<redacted>); This however, will not register it: //...
IReadOnlyDictionary<int, SlashCommandsExtension> slashCommands
= await DiscordClient.UseSlashCommandsAsync(SlashCommandsConfiguration);
DiscordClient.GuildAvailable += (sender, args) => DiscordClient_GuildAvailable(sender, args, slashCommands);
//...
private async Task DiscordClient_GuildAvailable(DiscordClient sender,
GuildCreateEventArgs args,
IReadOnlyDictionary<int, SlashCommandsExtension> slashCommands)
{
slashCommands.RegisterCommands<TestCommandModule>(args.Guild.Id);
} My best guess is this relates to this somewhat vague paragraph in the help documentation:
The "at runtime" thing seems a bit odd; surely the app is running the whole time, but you'd need to register commands at some point? Perhaps it refers to the I don't need to dynamically change the commands while the bot is running, but I would like to set non-global slash commands on startup. What am I missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You have to register your commands before connecting to the gateway. Like you said before |
Beta Was this translation helpful? Give feedback.
You have to register your commands before connecting to the gateway. Like you said before
ConnectAsync
. If you want to lock your commands to one specific guild, you should save the id in your config or hardcode it. If you want to register them for all guild then simply dont provide a id and they will be registered globally