Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Registering commands in the GuildAvailable event doesn't seem to work#1632

AnsweredbyPlerx2493
Metritutus asked this question inSupport
Discussion options

I'm attempting to register commands in theGuildAvailable event handler (which is how I did it with Discord.NET), however it doesn't seem to work.

I'm using theDiscordShardedClient approach. If I do the following, mytest command will be registered:

IReadOnlyDictionary<int,SlashCommandsExtension>slashCommands=awaitDiscordClient.UseSlashCommandsAsync(SlashCommandsConfiguration);slashCommands.RegisterCommands<TestSlashCommandModule>(<redacted>);

This however, will not register it:

//...IReadOnlyDictionary<int,SlashCommandsExtension>slashCommands=awaitDiscordClient.UseSlashCommandsAsync(SlashCommandsConfiguration);DiscordClient.GuildAvailable+=(sender,args)=>DiscordClient_GuildAvailable(sender,args,slashCommands);//...privateasyncTaskDiscordClient_GuildAvailable(DiscordClientsender,GuildCreateEventArgsargs,IReadOnlyDictionary<int,SlashCommandsExtension>slashCommands){slashCommands.RegisterCommands<TestCommandModule>(args.Guild.Id);}

My best guess is this relates to this somewhat vague paragraph in thehelp documentation:

It does not support registering or editing commands at runtime. While you can make commands at runtime using the methods on the client, if you have a command class registered for that guild/globally if you're making global commands, it will be overwritten (therefore probably deleted) on the next startup due to the limitations of the bulk overwrite endpoint. If your usage of slash commands depends on dynamically registering commands, this extension will not work for you.

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 theDiscordClient being connected? Would this be prior toStartAsync() being called for theDiscordShardClient? If so, how are you supposed to get the guild ids to register the commands with without knowing them in advance and hard-coding them? If theGuildAvailable event happens too late for slash command registration, how do you register slash commands, when starting the bot, only for the guilds the bot is in (or specific guilds filtered based on some criteria) without hard-coding the guild ids or using global commands?

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?

You must be logged in to vote

You have to register your commands before connecting to the gateway. Like you said beforeConnectAsync. 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

Replies: 1 comment 5 replies

Comment options

You have to register your commands before connecting to the gateway. Like you said beforeConnectAsync. 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

You must be logged in to vote
5 replies
@Metritutus
Comment options

Ah, darn, that is unfortunate. I'm guessing this is an implementation detail specific to DSharpPlus, as Discord.NET didn't seem to have this limitation?

@akiraveliara
Comment options

it is an impl detail, but fwiw you can register your commands later and then refresh them

@Metritutus
Comment options

Ah, how does one go about refreshing slash commands if they've been registered later, other than by restarting the bot?

@akiraveliara
Comment options

calling the refresh function on the extension

@Metritutus
Comment options

Sorry for the delayed response. Thanks for your responses, cheers!

Answer selected byPlerx2493
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Support
Labels
None yet
3 participants
@Metritutus@Plerx2493@akiraveliara

[8]ページ先頭

©2009-2025 Movatter.jp