From d9fa69863252fded220d3edf7d6e44e60df27132 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 26 Aug 2025 00:05:37 +0000 Subject: [PATCH] ignore messages from the bot itself --- discord-bot.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/discord-bot.cpp b/discord-bot.cpp index 15d9944..592e613 100644 --- a/discord-bot.cpp +++ b/discord-bot.cpp @@ -73,10 +73,18 @@ int main() { }); bot.on_message_create([&bot](const dpp::message_create_t& event) { + // Ignore messages from the bot itself to prevent infinite loops + bot.log(dpp::ll_info, "author id: " + to_string(event.msg.author.id)); + bot.log(dpp::ll_info, "bot id: " + to_string(bot.me.id)); + if (event.msg.author.id == bot.me.id) { + bot.log(dpp::ll_info, "Ignoring message, author and bot id match"); + return; + } + // Check if the message has any attachments if (!event.msg.attachments.empty()) { // // Log that an attachment was found - bot.log(dpp::ll_info, "Message from " + event.msg.author.username + " contains attachments!"); + bot.log(dpp::ll_info, "Message from " + event.msg.author.username + " contains attachments!"); // You can iterate through the attachments if you need details about each one for (const auto& attachment : event.msg.attachments) { // @@ -124,7 +132,7 @@ int main() { void process_attachment(dpp::cluster& bot, const dpp::message_create_t& event, const dpp::attachment& attachment) { std::string local_filename = "temp_" + std::to_string(attachment.id) + "_" + attachment.filename; - + bot.request(attachment.url, dpp::http_method::m_get, [ &bot, event, local_filename, attachment](const dpp::http_request_completion_t& completion) { if (completion.status < 400) {