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!
- Note
- This tutorial makes use of callbacks. For more information about that, visit Using Callback Functions.
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;
}
That's it! Now, you should have something like this: