Discord API
This guide will walk you through connecting and customizing your Discord bots with API calls.
Last updated
This guide will walk you through connecting and customizing your Discord bots with API calls.
Last updated
All the endpoints used in the guide are available at the Discord Developer Documentation.
If you are new to BotWiz, and have not yet added your bot: click here to learn how! If you have any questions throughout or get stuck, feel free to visit our Support Server.
Head to the Discord Developers Documentation and have a look around the page and get comfortable with it. The search bar on the left hand side is your best friend! (Ctrl + k)
All the info about this API endpoint can be found here: 🔗 https://discord.com/developers/docs/resources/channel#get-channel-messages
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.
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[response]}
{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.
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.
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).
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.
To display the ID of the latest message, add the variable {api_get_msg[response.0.id]}
into your embed / message description.
All the info about this API endpoint can be found here: 🔗 https://discord.com/developers/docs/resources/channel#create-message
To get channel messages from a channel in your discord server, we need to use the following endpoint:
POST
https://discord.com/api/v10/channels/
CHANNEL-ID
/messages
You will need to replace CHANNEL-ID
with your guild channel ID.
For this guide our name for the API block will be post_msg.
The variable list at the bottom of the API setup page should now display the following:
{api_post_msg[response]}
{api_post_msg[status-code]}
{api_post_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.
The request body allows us to add JSON data to send to the request, enabling us to specify the details of the action we want to perform. In the context of the Discord API the request body can be used to define various parameters such as the content of a message.
To be able to create a plain text message, all we need to add into the request body is the content, see the table below.
If you have completed all the steps above, head to the Test Request tab, and press "Test". You should know see a Message Object, and if you check your discord channel, you should see a message has been sent!
To send embed messages via Discord API it's slightly different than a plain text message. The key is changed to embeds and the value becomes an array of embed objects. That simply just means the embeds parameter can process multiple values, instead of just 1.
If you've created any embed webhook with JSON data, it's exactly the same as that.
To send an embed message that has a description of "My first API embed message" with a footer of "Sent with Botwiz.dev" follow the structure below:
"color" has to be a decimal number, it does not accept hexadecimal values (#fffff, #222). You can use a "Hexadecimal to decimal" converter to convert the hex value to decimal.
To get JSON data for an embed you want to create, you can build the embed through our free embed builder tool and retrieve the JSON data by pressing View JSON.