Created
May 3, 2020 07:41
-
-
Save Androz2091/b49ecff0606dedd4fc5a5e61a96ac126 to your computer and use it in GitHub Desktop.
How to send messages via a bot when someone click a button your website?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create our client | |
const Discord = require('discord.js'); | |
const client = new Discord.Client(); | |
// Login to Discord | |
client.login('TOKEN'); | |
// Create our express server | |
const express = require('express'); | |
const app = express(); | |
// Listen port 3000 | |
app.listen(3000); | |
// So, now when | |
app.get("/send", function (req, res) { | |
client.channels.get('YOUR CHANNEL ID').send('hello!'); | |
}); | |
// If the server IP is 12.34.567.890 | |
// when you will make a request to 12.34.567.890:3000/send | |
// the bot will send "hello!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Coucou</title> | |
</head> | |
<body> | |
<button onclick="send()">Send a message with the bot!</button> | |
<script> | |
function send() { | |
const xhttp = new XMLHttpRequest(); | |
xhr.open('GET', '12.34.567.890:3000/send'); | |
xhr.send(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment