Skip to content

Instantly share code, notes, and snippets.

@Androz2091
Created May 3, 2020 07:41
Show Gist options
  • Save Androz2091/b49ecff0606dedd4fc5a5e61a96ac126 to your computer and use it in GitHub Desktop.
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?
// 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!"
<!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