//
<!DOCTYPE html>
<html>
<head>
<title>Invite My Discord Bot</title>
</head>
<body>
<button onclick="inviteBot()">Invite My Bot</button>
<script>
function inviteBot() {
const serverUrl = 'http://localhost:3000/invite-bot';
// Make a request to your local server
fetch(serverUrl)
.then(response => {
if (response.ok) {
alert('Bot invited successfully!');
} else {
alert('Failed to invite bot. Please try again later.');
}
})
.catch(error => {
console.error('Error occurred:', error);
alert('An error occurred while inviting the bot.');
});
}
</script>
</body>
</html>
const express = require('express');
const axios = require('axios')
const app = express();
const clientId = '';
const token = '';
const guildId = '';
// API endpoint for bot invitation
app.get('/invite-bot', async (req, res) => {
try {
const response = await axios.put(`https://discord.com/api/v9/guilds/${guildId}/members/${clientId}`, {
access_token: token
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bot ${token}`
}
});
if (response.status === 201) {
res.send('Bot invited successfully!');
} else {
throw new Error(`Failed to invite bot: ${response.statusText}`);
}
} catch (error) {
console.error('Error occurred:', error);
res.status(500).send('An error occurred while inviting the bot.');
}
});
// Start the server
const port = 3000;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
Attached is the code for the Server and the Index it is local I am just trying to get it to join my server(guild) it is for a discord.js bot
ClientId, Token, and GuildID are removed for obvious reasons the axios error code that comes back is a long "403" Code I've been troubleshooting this for about 2-3 hours now and dont know what im doing wrong
Thank you