mirror of
https://github.com/HappyTanuki/BumbleCee.git
synced 2025-12-18 21:23:29 +00:00
스킵 구현
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
\page application-command-autocomplete Slash Command Autocompletion
|
||||
|
||||
Discord now supports sending auto completion lists for slash command choices. To use this feature you can use code such as the example below:
|
||||
|
||||
\include{cpp} autocomplete.cpp
|
||||
@@ -0,0 +1,7 @@
|
||||
\page clearing_slashcommands Clearing Registered Commands
|
||||
|
||||
After a while of creating commands, you may start to wonder "hm, how can I clear these?". Well, this tutorial covers it! All you have to do is simply call dpp::cluster::global_bulk_command_delete or dpp::cluster::guild_bulk_command_delete.
|
||||
|
||||
\note Clearing **global commands** will only clear commands that were **made globally**, same goes for the opposite way round. The example will demonstrate using both functions.
|
||||
|
||||
\include{cpp} clearing_slashcommands.cpp
|
||||
@@ -0,0 +1,15 @@
|
||||
\page commandhandler Using a Command Handler Object
|
||||
|
||||
If you have many commands in your bot, and want to handle commands from multiple sources, you should consider instantiating a dpp::commandhandler object. This object can be used to automatically route
|
||||
commands and their parameters to functions in your program. A simple example of using this object to route commands is shown below, and will
|
||||
route both the /ping (global slash command) and .ping (prefixed channel message command) to a lambda where a reply can be generated.
|
||||
|
||||
\note This example automatically hooks the dpp::cluster::on_message_create and dpp::cluster::on_slashcommand events. This can be overridden if needed to allow you to still make use of these functions for your own code, if you need to do this please see the constructor documentation for dpp::commandhandler.
|
||||
|
||||
Note that because the dpp::commandhandler::add_command method accepts a `std::function` as the command handler, you may point a command handler
|
||||
at a simple lambda (as shown in this example), a function pointer, or an instantiated class method of an object. This is extremely flexible
|
||||
and allows you to decide how and where commands should be routed, either to an object oriented system or to a lambda based system.
|
||||
|
||||
\warning As of [August 30th, 2022](https://support-dev.discord.com/hc/en-us/articles/6025578854295-Why-We-Moved-to-Slash-Commands), you are advised to only be using slash commands, not messages for commands. To prevent the command handler from handling commands with messages, you should only use the "/" prefix. If you wish to still use messages for commands, this tutorial will still cover it but, again, it is discouraged by Discord.
|
||||
|
||||
\include{cpp} commandhandler.cpp
|
||||
@@ -0,0 +1,29 @@
|
||||
\page slashcommands Using Slash Commands and Interactions
|
||||
|
||||
Slash commands and interactions are a newer feature of Discord which allow a bot's commands to be registered centrally within the system and for users to easily explore and get help with available commands through the client itself.
|
||||
|
||||
To add a slash command you should use the dpp::cluster::global_command_create method for global commands (available to all guilds) or dpp::cluster::guild_command_create to create a local command (available only to one guild). If you want to add many commands, it is advised to use the dpp::cluster::global_bulk_command_create method for global commands or the dpp::cluster::guild_bulk_command_create method for local commands.
|
||||
|
||||
\note dpp::cluster::global_bulk_command_create and dpp::cluster::guild_bulk_command_create will delete any previous commands that were registered. For example, if you call dpp::cluster::global_bulk_command_create twice with two different sets then the first set of commands will be created, then when the second set is called, the first set will be deleted, leaving only the second set.
|
||||
|
||||
When a user issues these commands the reply will arrive via the `on_slashcommand` event which you can hook into, and take action when you see your commands. It is possible to reply to an interaction by using either the dpp::interaction_create_t::reply method, or by manually instantiating an object of type dpp::interaction_response and attaching a dpp::message object to it.
|
||||
|
||||
dpp::interaction_create_t::reply has two overloaded versions of the method, one of which accepts simple `std::string` replies, for basic text-only messages (if your message is 'ephemeral' you must use this) and one which accepts a dpp::message for more advanced replies. Please note that at present, Discord only supports a small subset of message and embed features within an interaction response object.
|
||||
|
||||
This first example goes over creating a single command globally.
|
||||
|
||||
\include{cpp} slashcommands1.cpp
|
||||
|
||||
This second example goes over creating a single command but only for a guild, this means that the command can not be accessed anywhere else but the guild specified.
|
||||
|
||||
\include{cpp} slashcommands2.cpp
|
||||
|
||||
This third example goes over creating four commands globally, using the bulk create method.
|
||||
|
||||
\include{cpp} slashcommands3.cpp
|
||||
|
||||
This fourth example goes over creating four commands but only for a guild.
|
||||
|
||||
\include{cpp} slashcommands4.cpp
|
||||
|
||||
\note For demonstration purposes, and small bots, this code is OK, but in the real world once your bot gets big, it's not recommended to create slash commands in the `on_ready` event even when it's inside dpp::run_once as, if you re-run your bot multiple times or start multiple clusters, you will quickly get rate-limited! You could, for example, add a commandline parameter to your bot (`argc`, `argv`) so that if you want the bot to register commands it must be launched with a specific command line argument.
|
||||
@@ -0,0 +1,5 @@
|
||||
\page subcommands Using Sub-Commands in Slash Commands
|
||||
|
||||
This demonstrates how to use sub-commands within slash commands. Also shown below is an example of how to get a "resolved" parameter without having to use the cache or an extra API call.
|
||||
|
||||
\include{cpp} subcommands.cpp
|
||||
@@ -0,0 +1,10 @@
|
||||
\page discord-application-command-file-upload Using File Parameters for Application Commands (Slash Commands)
|
||||
|
||||
The program below demonstrates how to use the 'file' type parameter to an application command (slash command).
|
||||
You must first get the `file_id` via `std::get`, and then you can find the attachment details in the 'resolved'
|
||||
section, `event.command.resolved`.
|
||||
|
||||
The file is uploaded to Discord's CDN so if you need it locally you should fetch the `.url` value, e.g. by using
|
||||
something like dpp::cluster::request().
|
||||
|
||||
\include{cpp} upload_parameter.cpp
|
||||
Reference in New Issue
Block a user