Failed to fetch error in @discordjs/rest

Hi, I'm using @discordjs/rest & discord-api-types, I'm following the documentation, but for some reason, I'm getting Failed to fetch error.
try {
// Get the guild member data to ensure the user is part of the guild
const memberData = await rest.get(Routes.guildMember(guildId, userId));
console.log(memberData);

if (memberData) {
// Add the role to the user
await rest.put(Routes.guildMemberRole(guildId, userId, roleId));

console.log(`Successfully added role to user with ID: ${userId}`);
} else {
console.error(`User with ID ${userId} is not a member of the guild.`);
}
} catch (error) {
console.error(error);
}
try {
// Get the guild member data to ensure the user is part of the guild
const memberData = await rest.get(Routes.guildMember(guildId, userId));
console.log(memberData);

if (memberData) {
// Add the role to the user
await rest.put(Routes.guildMemberRole(guildId, userId, roleId));

console.log(`Successfully added role to user with ID: ${userId}`);
} else {
console.error(`User with ID ${userId} is not a member of the guild.`);
}
} catch (error) {
console.error(error);
}
31 Replies
d.js toolkit
d.js toolkitβ€’8mo 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
InFiNiTy
InFiNiTyβ€’8mo ago
So would you give error with stacktrace to better understand the issue?
Farhan
Farhanβ€’8mo ago
No description
InFiNiTy
InFiNiTyβ€’8mo ago
hmm does memberData return anything?
Farhan
Farhanβ€’8mo ago
none, actually the error is coming from memberData
InFiNiTy
InFiNiTyβ€’8mo ago
maybe try to put in rest options makeRequest: fetch
treble/luna
treble/lunaβ€’8mo ago
Make sure both memberId and guildId are valid snowflakes
Farhan
Farhanβ€’8mo ago
yeah, I checked it. seems to be both Ids are valid
Farhan
Farhanβ€’8mo ago
No description
Farhan
Farhanβ€’8mo ago
here is my full code can you elaborate more?
InFiNiTy
InFiNiTyβ€’8mo ago
in line 10 after key option in new REST call, so version: '10' put another option makeRequest: fetch
InFiNiTy
InFiNiTyβ€’8mo ago
by the way why the heck you either import and require packages?
No description
Farhan
Farhanβ€’8mo ago
my godddd, damn. I didn't notice monkaS
InFiNiTy
InFiNiTyβ€’8mo ago
np just curious πŸ˜…
Farhan
Farhanβ€’8mo ago
but also getting the same error tho πŸ™‚
Want results from more Discord servers?
Add your server