01_02
This commit is contained in:
@@ -17,4 +17,6 @@ foreach(cmake_file ${CMAKE_FILES})
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/00_project")
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/00_project")
|
||||||
|
|
||||||
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/01_first_bot")
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/01_first_bot")
|
||||||
|
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src/01_basics/02_embeds")
|
||||||
|
|||||||
15
src/01_basics/02_embeds/CMakeLists.txt
Normal file
15
src/01_basics/02_embeds/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(dppbots)
|
||||||
|
set(example_name "01_02_embeds")
|
||||||
|
message("Setting up ${example_name}")
|
||||||
|
add_executable(${example_name} "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
|
||||||
|
target_include_directories(${example_name} PUBLIC
|
||||||
|
"${dpp_SOURCE_DIR}/include"
|
||||||
|
"${dotenv-cpp_SOURCE_DIR}/include/laserpants"
|
||||||
|
|
||||||
|
)
|
||||||
|
target_link_libraries(${example_name}
|
||||||
|
dpp
|
||||||
|
dotenv
|
||||||
|
)
|
||||||
|
SET_OUTPUT_NAMES(${example_name})
|
||||||
82
src/01_basics/02_embeds/src/main.cpp
Normal file
82
src/01_basics/02_embeds/src/main.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include <cluster.h>
|
||||||
|
#include <colors.h>
|
||||||
|
#include <dispatcher.h>
|
||||||
|
#include <dotenv/dotenv.h>
|
||||||
|
#include <dpp/dpp.h>
|
||||||
|
#include <message.h>
|
||||||
|
#include <once.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// Load in the .env file
|
||||||
|
dotenv::init();
|
||||||
|
// Get the discord token from the environment
|
||||||
|
std::string botToken = std::getenv("DISCORD_TOKEN");
|
||||||
|
|
||||||
|
// Create a bot cluster
|
||||||
|
dpp::cluster bot(botToken);
|
||||||
|
|
||||||
|
// Set the bot logging callback to a default cout logger
|
||||||
|
bot.on_log(dpp::utility::cout_logger());
|
||||||
|
|
||||||
|
// Set the slashcommand callback
|
||||||
|
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
|
||||||
|
// Filter the slashcommand by name
|
||||||
|
if (event.command.get_command_name() == "embed") {
|
||||||
|
// Create the embed object
|
||||||
|
dpp::embed embed =
|
||||||
|
dpp::embed()
|
||||||
|
// Set the color of the embed
|
||||||
|
// This sets the color of the line
|
||||||
|
// on the left side
|
||||||
|
.set_color(dpp::colors::sti_blue)
|
||||||
|
// Set the title
|
||||||
|
.set_title("Title")
|
||||||
|
// Set the title url
|
||||||
|
.set_url("https://dpp.dev")
|
||||||
|
// Set the author info
|
||||||
|
.set_author("Firewire", "https://dpp.dev",
|
||||||
|
"https://dpp.dev/DPP-Logo.png")
|
||||||
|
.set_description("Description")
|
||||||
|
// Set the thumbnail, this is a small image off the right
|
||||||
|
.set_thumbnail("https://dpp.dev/DPP-Logo.png")
|
||||||
|
// Add some regular and inline fields
|
||||||
|
.add_field("Regular field title", "Value")
|
||||||
|
.add_field("Inline field title", "Value", true)
|
||||||
|
.add_field("Inline field title", "Value", true)
|
||||||
|
// Set the main image, this will be the center large image
|
||||||
|
.set_image("https://dpp.dev/DPP-Logo.png")
|
||||||
|
// Set the footer
|
||||||
|
.set_footer(dpp::embed_footer()
|
||||||
|
.set_text("Footer text")
|
||||||
|
.set_icon("https://dpp.dev/DPP-Logo.png"))
|
||||||
|
// Add a timestamp,
|
||||||
|
// time(<arg>) returns a timer of <arg> seconds
|
||||||
|
// using a 0 for the arg just returns the current time
|
||||||
|
.set_timestamp(time(0));
|
||||||
|
|
||||||
|
// Create a message using the embed
|
||||||
|
dpp::message msg(event.command.channel_id, embed);
|
||||||
|
// Send the message as a reply
|
||||||
|
event.reply(msg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set the bot on_ready to create a the global commands
|
||||||
|
bot.on_ready([&bot](const dpp::ready_t& event) {
|
||||||
|
// Only run the register_bot_commands once
|
||||||
|
// (If the bot is disconnected from the discord gateway,
|
||||||
|
// on_ready() is called once reconnected.
|
||||||
|
// We dont want to re-register when this happens)
|
||||||
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
|
bot.global_command_create(
|
||||||
|
dpp::slashcommand("embed", "Send an embed", bot.me.id));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start the bot
|
||||||
|
bot.start(dpp::st_wait);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user