I’m working on a feature for my bot that allows server moderators to remove all users from a given thread who have not sent a single message in that thread in the past 30 days. I have everything working so far, up to generating a list of ThreadMember objects representing the users I want to kick. However, when I call the remove() function on these objects, I’m met with:
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (C:UsersXXXXXDesktopDV Discord BotDVDiscordBot1node_modules@discordjsrestdistindex.js:933:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (C:UsersXXXXXDesktopDV Discord BotDVDiscordBot1node_modules@discordjsrestdistindex.js:712:14)
at async REST.request (C:UsersXXXXXDesktopDV Discord BotDVDiscordBot1node_modules@discordjsrestdistindex.js:1321:22)
at async ThreadMemberManager.remove (C:UsersXXXXXDesktopDV Discord BotDVDiscordBot1node_modulesdiscord.jssrcmanagersThreadMemberManager.js:111:5)
at async ThreadMember.remove (C:UsersXXXXXDesktopDV Discord BotDVDiscordBot1node_modulesdiscord.jssrcstructuresThreadMember.js:108:5) {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'DELETE',
url: 'https://discord.com/api/v10/channels/1181506798549741688/thread-members/114958895482404868',
requestBody: { files: undefined, json: undefined }
}
Here is how I have the feature currently implemented, if it helps. getThreadMsgsAfterDate
is a helper function that repeatedly runs fetch commands to grab as many messages as necessary, to get around the 100 messages cap per fetch.
let threadMems = await thread.members.fetch();
let time = new Date();
time.setDate(time.getDate() - 30);
msgs = await getThreadMsgsAfterDate(thread, time);
let idsFound = new Set();
msgs.forEach((obj) => {
idsFound.add(obj.author);
});
console.log(`Found ${idsFound.size} unique users in ${msgs.length} messages`);
let notInMostRecent = [];
threadMems.each(mem => {
if (!idsFound.has(mem.id)) {
notInMostRecent.push(mem);
}
});
console.log(`${notInMostRecent.length}/${threadMems.size} thread members were not found in the most recent messages`);
notInMostRecent.forEach((mem) => {
mem.remove(`Removed from thread: "${thread.name}" for inactivity. Please rejoin if you wish to continue using it.`);
});
I can confirm that everything works exactly as intended up to the mem.remove()
call, which gives me the error I posted above. Solutions I have attempted so far, based on google searching I have done:
- 2FA is enabled on my (the bot owner’s) Discord account
- The bot has been given the Manage Threads permission by the server owner
- The bot uses the GuildMembers gateway intent (and several others – let me know if you want the complete list)
Any advice is appreciated on additional things I can try. It’s possible I may also have gotten one of the above attempts wrong as well – feel free to call me out if I have.