You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docpages/example_programs/interactions_and_components.md
+3-2
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,12 @@
3
3
The example programs listed here demonstrate lots of things to do with interactions, application commands (slash commands) and message components. If you're looking to make your bot **modern and user friendly** these examples are what you need.
4
4
5
5
* \subpage slashcommands "Using Slash Commands and Interactions"
Copy file name to clipboardexpand all lines: docpages/example_programs/interactions_and_components/commandhandler.md
+6-3
Original file line number
Diff line number
Diff line change
@@ -5,24 +5,27 @@ prefixed channel messages) you should consider instantiating a dpp::commandhandl
5
5
commands and their parameters to functions in your program. A simple example of using this object to route commands is shown below, and will
6
6
route both the /ping (global slash command) and .ping (prefixed channel message command) to a lambda where a reply can be generated.
7
7
8
-
\noteThis 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.
8
+
\noteThis 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.
9
9
10
10
Note that because the dpp::commandhandler::add_command method accepts a `std::function` as the command handler, you may point a command handler
11
11
at a simple lambda (as shown in this example), a function pointer, or an instantiated class method of an object. This is extremely flexible
12
12
and allows you to decide how and where commands should be routed, either to an object oriented system or to a lambda based system.
13
13
14
+
\warning As of August 30th, 2022, 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.
15
+
14
16
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
15
17
#include <dpp/dpp.h>
16
18
17
19
int main()
18
20
{
19
-
dpp::cluster bot("token");
21
+
/* If your bot only uses the "/" prefix, you can remove the intents here. */
/* Create command handler, and specify prefixes */
24
27
dpp::commandhandler command_handler(&bot);
25
-
/* Specifying a prefix of "/" tells the command handler it should also expect slash commands */
28
+
/* Specifying a prefix of "/" tells the command handler it should also expect slash commands. Remove the .add_prefix(".") if you wish to only make it a slash command */
Sometimes, you may want to listen out for a message, rather than a command. This could be used for many cases like a spam filter, a bot that would respond to movie quotes with gifs, or a chat bot! However, in this page, we'll be using this to create a moderation filter (detect bad words).
4
+
5
+
\warning As of August 30th, 2022, Discord made Message Content a privileged intent. Whilst this means you can still use prefixed messages as commands, Discord does not encourage this and heavily suggests you use [slash commands](/slashcommands.html). If you wish to create commands, use [slash commands](/slashcommands.html), not messages.
6
+
7
+
~~~~~~~~~~{.cpp}
8
+
#include <dpp/dpp.h>
9
+
10
+
int main()
11
+
{
12
+
/* Create the bot, but with our intents so we can use messages. */
Copy file name to clipboardexpand all lines: docpages/example_programs/interactions_and_components/slashcommands.md
-2
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,6 @@ When a user issues these commands the reply will arrive via the `on_slashcommand
10
10
11
11
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.
12
12
13
-
\note You can also use the unified command handler, which lets you combine channel based message commands and slash commands under the same lambda with the same code like they were one and the same. Note that after August of 2022 Discord will be discouraging bots from using commands that are prefixed messages via means of a privileged message intent. It is advised that you exclusively use slash commands, or the unified handler with only a prefix of "/" going forward for any new bots you create and look to migrating existing bots to this setup.
14
-
15
13
This first example goes over creating a single command globally.
0 commit comments