To get channel messages from a channel in your discord server, we need to use the following endpoint:
GET
https://discord.com/api/v10/channels/
CHANNEL-ID
/messages
You will need to replace CHANNEL-ID
with your guild channel ID.
API Name
For this guide our name for the API block will be get_msg.
The variable list at the bottom of the API setup page should now display the following:
{api_get_msg[status-code]}
{api_get_msg[status-text]}
We now need to authorise our discord bot for discord to let us send a request to the endpoint.
You don't need to replace {bot_token}
with your actual bot token, as this variable will grab it automatically.
Test request
If you have completed all the steps above, head to the Test Request tab, and press "Test". You should now see the latest 100 messages in your channel.
You will also notice that is displays 0 - 99 responses, this is because the response is an Array and array indexes start at 0.
The test request will display an Invalid Form Body error if you have any variables in your URL, as the test request only accepts RAW input from all fields in the API request.
Getting the latest message
To get the latest message that was sent in the channel you have chosen, head to your URL Parameters and add the following:
Head back to your test request and click on "Test" again, you will now see only 1 response (the 0 index response).
Displaying the latest message
To display the latest message that was sent in that channel, create a new message component. For this guide we will be using an embed component.
In our Embed Description we will add the variable {api_get_msg[response.0.content]}
. This will display the latest message that was sent in the channel.
Displaying the ID of the message
To display the ID of the latest message, add the variable {api_get_msg[response.0.id]}
into your embed / message description.