Twijn
Twijn
DIAdiscord.js - Imagine an app
Created by Twijn on 8/27/2024 in #djs-questions
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
4 replies