javascript - HTML/PHP site communicating with discord bot

730

I am wondering if there is a way I can communicate using my HTML/PHP website to communicate with my discord bot. So what I want to do is to have some code or use another sollution to send messages to be sent by my discord bot. So for example: Lets say I write a line I want to be sent from my website every time someone submits a form, I then want a message to be sent by the discord bot saying something simular to "XXXX just submitted a form" in a specific channel.

I have tried seaching through youtube, stack overflow and other websites but didnt find a way to do it.

I already have the discord bot and its running using Visual Studio Code. I also have the website running.

Just wondering if theres a way to do this.

5

Answer

Solution:

The solution to this is to use a webhook and download the extension CURL. Then do this in the PHP code:

$curl = curl_init("DISCORD API FOR WEBHOOK");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(array("content" => "MESSAGE")));
curl_exec($curl);

People are also looking for solutions to the problem: php - Unable to write cache file

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.