How to create a thread with user permission for viewing?

I use members.add, but I want to create the Thread With "permissionwrite" discord.js v14.14.1
async function createThread(interaction, produtos) {
const existingThread = interaction.channel.threads.cache.find(x => x.name === `🛒・${interaction.user.username}・${interaction.user.id}`);

if (existingThread) {
const actionRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setURL(`https://discord.com/channels/${interaction.guild.id}/${existingThread.id}`)
.setLabel('Ir para o carrinho')
.setStyle(5)
);
await interaction.editReply({ content: `❌ Você já possui um carrinho aberto.`, components: [actionRow] });
return null;
}

const novaThread = await interaction.channel.threads.create({
name: `🛒・${interaction.user.username}・${interaction.user.id}`,
autoArchiveDuration: 60,
type: ChannelType.PrivateThread
});

await novaThread.members.add(interaction.user.id);
return novaThread;
}
async function createThread(interaction, produtos) {
const existingThread = interaction.channel.threads.cache.find(x => x.name === `🛒・${interaction.user.username}・${interaction.user.id}`);

if (existingThread) {
const actionRow = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setURL(`https://discord.com/channels/${interaction.guild.id}/${existingThread.id}`)
.setLabel('Ir para o carrinho')
.setStyle(5)
);
await interaction.editReply({ content: `❌ Você já possui um carrinho aberto.`, components: [actionRow] });
return null;
}

const novaThread = await interaction.channel.threads.create({
name: `🛒・${interaction.user.username}・${interaction.user.id}`,
autoArchiveDuration: 60,
type: ChannelType.PrivateThread
});

await novaThread.members.add(interaction.user.id);
return novaThread;
}
2 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!
Syjalo
Syjalo2mo ago
Threads don't have permissions. You have to add members
Want results from more Discord servers?
Add your server