jorisvddonk / node-red-contrib-discord

Node-red nodes that allow you to interact with Discord.
15 stars 19 forks source link

Reïntroduce useful data in `msg.author` and `msg.channel` #5

Closed jorisvddonk closed 5 years ago

jorisvddonk commented 7 years ago

Since v3.0.0, useful data was removed from msg.author and msg.channel. These properties used to be objects containing things like the message author's (nick)name and other useful things.

Unfortunately, since the specific implementation was causing issues, the properties were changed to be the IDs of the author and channel. The result is that in v3.0.0, in order to retrieve a user's name, one has to inject the Discord.js client via the discordClient node, use it to retrieve the user object's name (msg.author_username = msg.discord.users.get(msg.author).username), destroy the discordClient to allow message splitting (delete msg.discord) and then do whatever you want with the username. Not ideal.

Data that's already available when receiving a message on Discord should be available without having to inject the Discord.js client, and said data should be available in a JSON-serializable format to allow for message splitting. Ideally, the data should have some kind of node-red-contrib-discord internal type, so that one could send private messages to a user via a function node containing msg.target = msg.author chained to a discordSendMessage node.

Ryonez commented 5 years ago

Almost to years later, and this is what I came here for.

Having done some work with python bots, the amount of information missing that's normally attached to a message is surprising. Sure, enough for the absolute basics like sending a message back to the channel, and doing an author id check, but you can't even use the author's name in the reply without using an apparently deprecated node.

And I'm not sure what is happening with the node. Is it making an entirely new client to do these calls with?

I think adding information like the author's name, roles, permission even would be a great help. Even having the server the message came from would be good, making it easier to debug issues.

jorisvddonk commented 5 years ago

The discordClient node doesn't make a new client. Instead, it attaches an existing Discord.js client to a Node-red message, such that you can interact with it from within Function nodes. The reason why said node is deprecated is because it may cause issues; Node-red messages containing a Discord.js client can not be forked (cloned), and if this is attempted Node-red crashes completely.

That said, this issue should probably be addressed to make node-red-contrib-discord more useful and easy to develop with if you're not comfortable with node-red function nodes and are already familiar with the Discord.js API.

Ryonez commented 5 years ago

So the discordClient node attaches the client to the msg object so you can use it, then you use delete msg.discord to detach it before the msg object gets forked (I've never forked, so I don't know what this is exactly)?

Can other flows/node within the current flow use the client at the same time?

I'm pretty much completely new to NodeRed, and the Discord bot code I've used has been almost exclusively discord.py. Red seems extremely useful though and I'm integrating it into various little things.