Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added user_id to message_reaction_add_t #1376

Merged
merged 3 commits into from
Feb 2, 2025

Conversation

folle
Copy link
Contributor

@folle folle commented Feb 2, 2025

Adds an user_id field to message_reaction_add_t.
When we get the callback from adding a reaction in a DM, the payload is as follows:

{
	"t": "MESSAGE_REACTION_ADD",
	"s": 4,
	"op": 0,
	"d": {
		"user_id": "0000000000000000000",
		"type": 0,
		"message_id": "0000000000000000000",
		"message_author_id": "0000000000000000000",
		"emoji": {
			"name": "✅",
			"id": null
		},
		"channel_id": "0000000000000000",
		"burst": false
	}
}

This has no member or user information to fill the corresponding classes, making it impossible to get the user_id of the user that reacted.

Test code:

#include <cassert>
#include <memory>
#include <dpp/dpp.h>

#define TOKEN "ADD_BOT_TOKEN"
#define USER_ID ADD_USER_ID

class TestBot final {
public:
	TestBot() {
		bot_.on_ready([this](dpp::ready_t const& ready) { OnReady(ready); });
		bot_.on_message_reaction_add([this](dpp::message_reaction_add_t const& message_reaction_add) { OnMessageReactionAdd(message_reaction_add); });
	}
	~TestBot() = default;

	void Start() noexcept {
		bot_.start(dpp::st_wait);
	}

private:
	void OnMessageReactionAdd(dpp::message_reaction_add_t const& message_reaction_add) noexcept {
		assert(message_reaction_add.user_id == bot_.me.id);
	}

	void OnReady(dpp::ready_t const& ready) noexcept {
		bot_.direct_message_create(USER_ID, dpp::message("Test"), [this](dpp::confirmation_callback_t const& confirmation_callback) {
			auto const sent_message = confirmation_callback.get<dpp::message>();
			bot_.message_add_reaction(sent_message, "✅");
		});
	}

private:
	dpp::cluster bot_ = dpp::cluster(TOKEN, dpp::i_default_intents);
};

int main(const int argc, char const* const* const argv) {
	TestBot bot;
	bot.Start();

	return 0;
}

Code change checklist

  • I have ensured that all methods and functions are fully documented using doxygen style comments.
  • My code follows the coding style guide.
  • I tested that my change works before raising the PR.
  • I have ensured that I did not break any existing API calls.
  • I have not built my pull request using AI, a static analysis tool or similar without any human oversight.

@CLAassistant
Copy link

CLAassistant commented Feb 2, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added documentation Improvements or additions to documentation code Improvements or additions to code. labels Feb 2, 2025
Copy link

netlify bot commented Feb 2, 2025

Deploy Preview for dpp-dev ready!

Name Link
🔨 Latest commit f546c24
🔍 Latest deploy log https://app.netlify.com/sites/dpp-dev/deploys/679ee10153df3400081adc69
😎 Deploy Preview https://deploy-preview-1376--dpp-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@braindigitalis
Copy link
Contributor

message_reaction_add_t has reacting_user, which contains an id attribute. This is filled if you have the guild members intent. Is this not filled for you?

If there is no member, then you should fill the reacting_user.id with the received user_id, instead of creating a new attribute, this way it works in all situations.

See: https://discord.com/developers/docs/events/gateway-events#message-reaction-add

@folle
Copy link
Contributor Author

folle commented Feb 2, 2025

message_reaction_add_t has reacting_user, which contains an id attribute. This is filled if you have the guild members intent. Is this not filled for you?

If there is no member, then you should fill the reacting_user.id with the received user_id, instead of creating a new attribute, this way it works in all situations.

See: https://discord.com/developers/docs/events/gateway-events#message-reaction-add

It doesn't get filled for me, even with the guild members intent.
I added a new field because I saw that typing_start_t has both user_id and typing_user. I will update the PR to use reacting_user

@folle
Copy link
Contributor Author

folle commented Feb 2, 2025

Updated test code

#include <cassert>
#include <memory>
#include <dpp/dpp.h>

#define TOKEN "ADD_BOT_TOKEN"
#define USER_ID ADD_USER_ID

class TestBot final {
public:
	TestBot() {
		bot_.on_ready([this](dpp::ready_t const& ready) { OnReady(ready); });
		bot_.on_message_reaction_add([this](dpp::message_reaction_add_t const& message_reaction_add) { OnMessageReactionAdd(message_reaction_add); });
	}
	~TestBot() = default;

	void Start() noexcept {
		bot_.start(dpp::st_wait);
	}

private:
	void OnMessageReactionAdd(dpp::message_reaction_add_t const& message_reaction_add) noexcept {
		assert(message_reaction_add.reacting_user.id == bot_.me.id);
	}

	void OnReady(dpp::ready_t const& ready) noexcept {
		bot_.direct_message_create(USER_ID, dpp::message("Test"), [this](dpp::confirmation_callback_t const& confirmation_callback) {
			auto const sent_message = confirmation_callback.get<dpp::message>();
			bot_.message_add_reaction(sent_message, "✅");
		});
	}

private:
	dpp::cluster bot_ = dpp::cluster(TOKEN, dpp::i_all_intents);
};

int main(const int argc, char const* const* const argv) {
	TestBot bot;
	bot.Start();

	return 0;
}

@braindigitalis braindigitalis merged commit 9135957 into brainboxdotcc:dev Feb 2, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code Improvements or additions to code. documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants