How use DCC_EditMessage? (discord-connector)
# support-forum
b
I've been trying to understand for a few hours how I handle DCC_Message, and how I can edit a message in the future using DCC_EditMessage. Whoever is going to help, I ask you to put a simple example for me to understand.
w
Hi Carlos. When you use
DCC_Message(channel_id, "My message");
, it returns an ID which represents the "Message ID". Discord uses message ID's to do actions on, because it is not very efficient to search for entire messages every time you want to change them. So, you can for example save that message ID somewhere. For this easy example, a variable should do:
Copy code
c
msg_id = DCC_SendMessage(channel_id, "This is my message");
Then, later on, you use
DCC_EditMessage
to accomplish your goal:
Copy code
c
DCC_EditMessage(msg_id, "The new text you want to have in your message");
//----------------^^
Notes: Your discord bot need permission to edit these messages.
b
I understand, but apparently it doesn't work. I've tried all the ways and none of them work, is it a bug?
Copy code
cs
#include <a_samp>
#include <discord-connector>
#include <discord-command>

#define DCC_CHANNEL_TEST         ("1046909425392291950")

new DCC_Channel:channel_test = DCC_INVALID_CHANNEL;
new msg_id;

main(){}

public OnGameModeInit()
{
    channel_test = DCC_FindChannelById(DCC_CHANNEL_TEST);

    msg_id = DCC_SendChannelMessage(channel_test, "My message!");
    return 1;
}

DCMD:edit(user, channel, params[])
{
    DCC_EditMessage(DCC_Message:msg_id, "New message");
    return 1;
}
w
Could it be because you are not tagging the
new msg_id
and it is tagged inside the
DCC_EditMessage
? change to:
new DCC_Message:msg_id;
and
DCC_EditMessage(msg_id, "New message");
f
@worried-lighter-82731 i need this system
b
but @worried-lighter-82731 yes
new DCC_Message:msg_id;
w
did you add to the "new..." on top?
f
I want to add this to my gamemode and I don't know how
w
wrong place @future-library-96464 , go to #231799180127895553
b
I did some tests and saw that the
DCC_SendChannelMessage
function doesn't return the message id, just 1(true) or 0(false). This function could be so easy, just manipulating things by the already integrated ID via Discord, but it's so difficult, there's not even an explanation on their Github. The function says:
native DCC_EditMessage(DCC_Message:message, const content[], DCC_Embed:embed = DCC_Embed:0);
So it could be:
native DCC_EditMessage(messageid, const content[], DCC_Embed:embed = DCC_Embed:0);
w
https://github.com/maddinat0r/samp-discord-connector/blob/master/src/Message.cpp#L358-L373 Looks a whole lot like the ID is returned here. @dazzling-translator-76954 sorry about the ping, do you have any insight? I never used the connector more than posting a few messages with it.
b
I think it's an include bug, apparently the
DCC_EditMessage
function is new, it came in version 0.3.5, but that was 2 years ago, did the owner of discord-connector give up on the project?
d
there's no message in reality until discord tells us it was successfully created
This function could be so easy, just manipulating things by the already integrated ID via Discord
that would become a blocking call, which is why SendChannelMessage has a callback param available in which you can utilise the real message from there
w
Perfect 👌
d
I think this could have been easily solved almost 12 hours ago if you just looked at this:
native DCC_SendChannelMessage(DCC_Channel:channel, const message[], const callback[] = "", const format[] = "", {Float, _}:...);
!
was mostly used for reactions but there's a place to save the message id and use editmessage somewhere else
b
There really isn't anything that explains these things to novice programmers, but thanks for the help, I'll look into this function.
I got it, thanks for the help. @worried-lighter-82731 & @dazzling-translator-76954.
6 Views