ignore messages from the bot itself
This commit is contained in:
parent
05e1f5a52b
commit
d9fa698632
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user