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' });
}
});
the token is fine, it just keeps returning 401 not authorized, im not sure what to do
2 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server