brainboxdotcc / DPP

C++ Discord API Bot Library - D++ is Lightweight and scalable for small and huge bots!
https://dpp.dev/
Apache License 2.0
1.05k stars 159 forks source link

dpp::cluster on_message_create callback not does not trigger when cluster is created using i_message_content intent #1084

Closed BradleyAKern closed 6 months ago

BradleyAKern commented 6 months ago

I am using the distribution of DPP included with the windows-bot-template, an example implementation of a Discord bot using DPP that is linked on the official DPP site.

Whenever my cluster is constructed using the bot() constructor with only the required token argument, like so: dpp::cluster bot(tokenString); Everything works as expected. Every time a message is sent to a channel in my discord, the appropriate callback defined by the on_message_create() call to my cluster will trigger.

However, this also yields a warning message: WARN: You have attached an event to cluster::on_message_create() but have not specified the privileged intent dpp::i_message_content. Message content, embeds, attachments, and components on received guild messages will be empty.

The message seems pretty self explanatory. In the Discord Developer Portal, I have ensured that my bot has the Message Content Intent enabled underneath Privileged Gateway Intents. Then, I updated the creation of my cluster from the above code to this: dpp::cluster bot(tokenString, dpp::i_message_content);

After rebuilding and running my project, there are no warnings or errors, but also the callback from on_message_create() no longer gets called when a message is sent to my discord.

This is the entirety of the C++ program, with the bot token censored:

#include <string>
#include "MyBot.h"
#include <dpp/dpp.h>

int main()
{
    std::string tokenString = "token goes here";

    /* Create bot cluster */
    dpp::cluster bot(tokenString, dpp::i_message_content);

    /* Output simple log messages to stdout */
    bot.on_log(dpp::utility::cout_logger());

    bot.on_message_create([&bot](const dpp::message_create_t& event)
    {
        if (event.msg.author.id != bot.me.id)
        {
            std::cout << "Hello World\n";
            bot.message_create(dpp::message(event.msg.channel_id, "Hello World!"));
            return;
        }
    });

    bot.start(dpp::st_wait);

    return 0;
}

I am currently building and running my application on Windows 10 using Visual Studio Community 2022 with the C++20 standard. I am testing using the desktop Discord client.

raxyte commented 6 months ago

This creates the cluster with only the message content intent, without the default intents. You need to OR it with dpp::i_default_intents.

Jaskowicz1 commented 6 months ago

Following up from what @Axyte said, you can check out our documentation on this if you're confused! https://dpp.dev/detecting-messages.html

BradleyAKern commented 6 months ago

Sounds like an open and shut case, the problem was definitely that the cluster was being created without default intents. Thank you both for your help!

Jaskowicz1 commented 6 months ago

Sounds like an open and shut case, the problem was definitely that the cluster was being created without default intents. Thank you both for your help!

No problem!!