add members to thread

case "adduser": {
await interaction.reply({ content: `Please provide the ID of the user you want to add to the thread.`, ephemeral: bot.config.discordConfig.ephemeral });

const filter = m => m.author.id === interaction.user.id;
const collector = interaction.channel.createMessageCollector({ filter, time: 1500000 });
const thread = interaction.channel;

if (!thread) {
return interaction.reply({ content: 'Thread not found.', ephemeral: true });
}

collector.on('collect', async (m) => {
if (m.content.toLowerCase() === bot.language.cancel) {
await m.delete().catch(() => { });
collector.stop();
return interaction.reply({ content: language.ticketMaxTickets.cancel, ephemeral: bot.config.discordConfig.ephemeral }).catch(() => { });
}

const userId = m.content.trim();
const userToAdd = interaction.guild.members.cache.get(userId);

if (!userToAdd) {
return interaction.followUp('User not found or invalid ID.');
}
try {
await thread.members.add(userToAdd.user.id);
interaction.channel.send(`User ${userToAdd.user.tag} added to thread ${thread.id} successfully.`);
} catch (error) {
console.error('Error adding user to thread:', error);
interaction.channel.send('Error adding user to thread. Please try again later.');
}

collector.stop();
});

collector.on('end', (collected, reason) => {
if (reason === 'time') {
interaction.followUp('No response received. Command timed out.');
}
});

break;
}
case "adduser": {
await interaction.reply({ content: `Please provide the ID of the user you want to add to the thread.`, ephemeral: bot.config.discordConfig.ephemeral });

const filter = m => m.author.id === interaction.user.id;
const collector = interaction.channel.createMessageCollector({ filter, time: 1500000 });
const thread = interaction.channel;

if (!thread) {
return interaction.reply({ content: 'Thread not found.', ephemeral: true });
}

collector.on('collect', async (m) => {
if (m.content.toLowerCase() === bot.language.cancel) {
await m.delete().catch(() => { });
collector.stop();
return interaction.reply({ content: language.ticketMaxTickets.cancel, ephemeral: bot.config.discordConfig.ephemeral }).catch(() => { });
}

const userId = m.content.trim();
const userToAdd = interaction.guild.members.cache.get(userId);

if (!userToAdd) {
return interaction.followUp('User not found or invalid ID.');
}
try {
await thread.members.add(userToAdd.user.id);
interaction.channel.send(`User ${userToAdd.user.tag} added to thread ${thread.id} successfully.`);
} catch (error) {
console.error('Error adding user to thread:', error);
interaction.channel.send('Error adding user to thread. Please try again later.');
}

collector.stop();
});

collector.on('end', (collected, reason) => {
if (reason === 'time') {
interaction.followUp('No response received. Command timed out.');
}
});

break;
}
10 Replies
d.js toolkit
d.js toolkit2mo 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
Night Ghost
Night Ghost2mo ago
Error adding user to thread: DiscordAPIError[50001]: Missing Access
at handleErrors (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:1133:23)
at async SequentialHandler.queueRequest (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:963:14)
at async _REST.request (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:1278:22)
at async ThreadMemberManager.add (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\discord.js\src\managers\ThreadMemberManager.js:100:5)
at async MessageCollector.<anonymous> (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\src\components\buttons\ticket.js:445:21) {
requestBody: { files: undefined, json: undefined },
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v10/channels/1242985113894260867/thread-members/1058739292324765766'
}
Error adding user to thread: DiscordAPIError[50001]: Missing Access
at handleErrors (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:730:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:1133:23)
at async SequentialHandler.queueRequest (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:963:14)
at async _REST.request (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\@discordjs\rest\dist\index.js:1278:22)
at async ThreadMemberManager.add (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\node_modules\discord.js\src\managers\ThreadMemberManager.js:100:5)
at async MessageCollector.<anonymous> (C:\Users\mrpev\Desktop\[Projects]\Phil_MultiBot\src\components\buttons\ticket.js:445:21) {
requestBody: { files: undefined, json: undefined },
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v10/channels/1242985113894260867/thread-members/1058739292324765766'
}
d.js docs
d.js docs2mo ago
:guide: Popular Topics: Permissions (extended) - Implicit permissions Causes for "Missing Access": read more
Amgelo
Amgelo2mo ago
@Night Ghost ^^
Night Ghost
Night Ghost2mo ago
all ready has that perms it has admin
chewie 🌈
chewie 🌈2mo ago
Does the user have perms to see the channel the thread is in?
Night Ghost
Night Ghost2mo ago
yea
Night Ghost
Night Ghost2mo ago
No description
chewie 🌈
chewie 🌈2mo ago
The user to add doesn't have permission to view the channel.
No description
Night Ghost
Night Ghost2mo ago
um ty worked was the channel for reason it was updated