Reputation: 29
How can I connect my Discord bot to my HTML website?
I don't need a dashboard. I just need to show how many servers my bot is in. On my website, how can I do this and which backend language should I use?
Which is the best backend language for web development?
My HTML content:
<!DOCTYPE html>
<html>
<head>
<div class="topnav">
<a class="active" href="#home">Home</a>
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Beast Bot</title>
</head>
<body>
<div class="container">
<div class="title">
<P>Beast Bot :)</P>
<img class="img" src="images/kisspng-portable-network-graphics-computer-icons-transpare-braingoodgames-5c9d9c5093e378.8617067815538330406058.png">
</div>
</div>
</div>
</body>
</html>
Upvotes: 1
Views: 7715
Reputation: 179
You can use an API to fetch data from your bot's back end. Frameworks like Express.js are great for making a REST API from scratch.
Upvotes: 1
Reputation: 53
I would use client.guilds.size
to get the amount of servers it's in. Assuming the web server and the bot are on the same server then, I would write the raw count of the amount of servers it's in to a file that the public can access from a browser.
Using jQuery (by adding <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
to your head) you can do a GET request to the publicly accessible URL that has that number, like this:
$.get("/path/to/data", data => {
// Your code here to display it. The data variable will have the page's content
})
Upvotes: 4