Issue adding user to guild with GuildMemberManager#add

Having an issue trying to have a member join using GuildMemberManager#add
utils.CommunicationManager.on("addUser", async (data, reply) => {
/*
In this, data.userId is confirmed to be my user ID (267380687345025025)
data.accessToken is confirmed to be a legitimate access token with the guilds.join scope.
*/
try {
const guild = await client.guilds.fetch(config.discord.mcp_guild);
await guild.members.add(data.userId, {
accessToken: data.accessToken,
fetchWhenExisting: true,
});
reply({});
} catch(err) {
console.error(`Error while adding user to guild:`);
console.error(err);
}
});
utils.CommunicationManager.on("addUser", async (data, reply) => {
/*
In this, data.userId is confirmed to be my user ID (267380687345025025)
data.accessToken is confirmed to be a legitimate access token with the guilds.join scope.
*/
try {
const guild = await client.guilds.fetch(config.discord.mcp_guild);
await guild.members.add(data.userId, {
accessToken: data.accessToken,
fetchWhenExisting: true,
});
reply({});
} catch(err) {
console.error(`Error while adding user to guild:`);
console.error(err);
}
});
Regardless, the error I keep getting is:
Error while adding user to guild:
TypeError: Cannot read properties of undefined (reading 'id')
at GuildMemberManager._add (/Users/tyler/GitHub/mcp/discord/node_modules/discord.js/src/managers/GuildMemberManager.js:39:52)
at GuildMemberManager.add (/Users/tyler/GitHub/mcp/discord/node_modules/discord.js/src/managers/GuildMemberManager.js:137:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/tyler/GitHub/mcp/discord/app.js:18:3
Error while adding user to guild:
TypeError: Cannot read properties of undefined (reading 'id')
at GuildMemberManager._add (/Users/tyler/GitHub/mcp/discord/node_modules/discord.js/src/managers/GuildMemberManager.js:39:52)
at GuildMemberManager.add (/Users/tyler/GitHub/mcp/discord/node_modules/discord.js/src/managers/GuildMemberManager.js:137:14)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/tyler/GitHub/mcp/discord/app.js:18:3
Using discord.js 14.15.3
3 Replies
d.js toolkit
d.js toolkit4mo 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 OP
Syjalo
Syjalo4mo ago
This is already fixed in the dev version. Will be in the next release
Twijn
TwijnOP4mo ago
Thank you! Will wait till then
Want results from more Discord servers?
Add your server