Farhan
Farhan
DIAdiscord.js - Imagine an app
Created by Farhan on 1/17/2024 in #djs-questions
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);
}
50 replies