01 - 03
All checks were successful
Build / Build (push) Successful in 3m28s

This commit is contained in:
2026-06-06 19:46:59 -04:00
parent ab41d81b2d
commit 97df4330f3

View File

@@ -1,18 +1,81 @@
#include <appcommand.h>
#include <cluster.h> #include <cluster.h>
#include <dispatcher.h> #include <dispatcher.h>
#include <dotenv/dotenv.h> #include <dotenv/dotenv.h>
#include <dpp/dpp.h> #include <dpp/dpp.h>
#include <message.h>
#include <once.h>
#include <restresults.h>
#include <snowflake.h>
#include <cstdlib> #include <cstdlib>
int main() { int main() {
dotenv::init(); dotenv::init();
std::string botToken = std::getenv("DISCORD_BOT"); std::string botToken = std::getenv("DISCORD_TOKEN");
if (botToken.empty()) {
std::cout
<< "Failed to load the discord token from .env or the environment"
<< std::endl;
exit(EXIT_FAILURE);
}
dpp::cluster bot(botToken); dpp::cluster bot(botToken);
bot.on_log(dpp::utility::cout_logger()); bot.on_log(dpp::utility::cout_logger());
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
if (event.command.get_command_name() == "pm") {
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"));
}
bot.direct_message_create(
user, dpp::message("Here's a private message!"),
[event, user](const dpp::confirmation_callback_t& callback) {
if (callback.is_error()) {
if (user == event.command.get_issuing_user().id) {
event.reply(
dpp::message("I couldnt send you a message.")
.set_flags(dpp::m_ephemeral));
} else {
event.reply(
dpp::message(
"I couldnt send a message to that user. "
"Please check that is a valid user.")
.set_flags(dpp::m_ephemeral));
}
return;
}
if (user == event.command.get_issuing_user().id) {
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 private message to that user.")
.set_flags(dpp::m_ephemeral));
}
});
}
});
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
dpp::slashcommand command("pm", "Send a private message.",
bot.me.id);
command.add_option(dpp::command_option(
dpp::co_mentionable, "user", "The user to message", false));
bot.global_command_create(command);
}
});
bot.start(dpp::st_wait); bot.start(dpp::st_wait);
return 0; return 0;