ShadyMoon
DIAdiscord.js - Imagine an app
•Created by ShadyMoon on 10/22/2024 in #djs-questions
Guilds request AI
app.get('/users/guilds', async (req, res) => {
const token = req.cookies.token;
console.log('Token received:', token);
if (!token) {
return res.status(401).json({ message: 'No token provided' });
}
try {
const decoded = jwt.verify(token, JWT_SECRET);
console.log('Decoded token:', decoded);
const accessToken = decoded.accessToken || token;
if (!accessToken) {
return res.status(401).json({ message: 'Access token not found in decoded token' });
}
const guildsResponse = await axios.get('https://discord.com/api/users/@me/guilds', {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
const guilds = guildsResponse.data;
return res.status(200).json(guilds);
} catch (error) {
console.error('Error during token verification or fetching guilds:', error);
if (error.response) {
return res.status(error.response.status).json({ message: error.response.data.message });
}
return res.status(403).json({ message: 'Invalid token or error fetching guilds' });
}
});
app.get('/users/guilds', async (req, res) => {
const token = req.cookies.token;
console.log('Token received:', token);
if (!token) {
return res.status(401).json({ message: 'No token provided' });
}
try {
const decoded = jwt.verify(token, JWT_SECRET);
console.log('Decoded token:', decoded);
const accessToken = decoded.accessToken || token;
if (!accessToken) {
return res.status(401).json({ message: 'Access token not found in decoded token' });
}
const guildsResponse = await axios.get('https://discord.com/api/users/@me/guilds', {
headers: {
Authorization: `Bearer ${accessToken}`
}
});
const guilds = guildsResponse.data;
return res.status(200).json(guilds);
} catch (error) {
console.error('Error during token verification or fetching guilds:', error);
if (error.response) {
return res.status(error.response.status).json({ message: error.response.data.message });
}
return res.status(403).json({ message: 'Invalid token or error fetching guilds' });
}
});
3 replies
DIAdiscord.js - Imagine an app
•Created by ShadyMoon on 10/13/2024 in #djs-questions
Bot command listing on profile
22 replies