Sometimes it's simply not enough to ping someone in a server with a message, and we get that. That's why you can private message people! This tutorial will cover how to make a command that will either message the author of the command or message a specified user!
#include <dpp/dpp.h>
int main() {
dpp::snowflake user;
if (event.get_parameter("user").index() == 0) {
user = event.command.get_issuing_user().id;
} else {
user = std::get<dpp::snowflake>(event.get_parameter("user"));
}
if (callback.is_error()) {
if (user == event.command.get_issuing_user().id) {
event.reply(dpp::message("I couldn't send you a message.").set_flags(dpp::m_ephemeral));
} else {
event.reply(dpp::message("I couldn't send a message to that user. Please check that is a valid user!").set_flags(dpp::m_ephemeral));
}
return;
}
event.reply(dpp::message("I've sent you a private message.").set_flags(dpp::m_ephemeral));
} else {
event.reply(dpp::message("I've sent a message to that user.").set_flags(dpp::m_ephemeral));
}
});
}
});
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(command);
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:80
const dpp::user & get_issuing_user() const
Get the user who issued this command.
std::string get_command_name() const
Get the command name for a command interaction.
snowflake id
Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID,...
Definition: managed.h:39
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:1342
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ co_mentionable
A mentionable (users and roles).
Definition: appcommand.h:94
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:63
Each command option is a command line parameter. It can have a type (see dpp::command_option_type),...
Definition: appcommand.h:203
The results of a REST call wrapped in a convenient struct.
Definition: restresults.h:255
interaction command
command interaction
Definition: dispatcher.h:678
Represents messages sent and received on Discord.
Definition: message.h:2016
Session ready.
Definition: dispatcher.h:961
User has issued a slash command.
Definition: dispatcher.h:695