This snippet allows you to use your bot to create a new thread in any channel with a custom name. To set up go to the Slash Command Builder and make a createthread command with a required string variable that will be the thread name. Only members with the MANAGE_THREADS permission will be able to use this command. IF YOU NEED HELP SETTING UP, you can ping @Zeno in the Autocode Discord for support. Hope you enjoy!
// authenticates you with the API standard library
// type `await lib.` to display API autocomplete
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let isMANAGE_THREADS =
(context.params.event.member.permissions & (1 << 34)) === 1 << 34;
if (isMANAGE_THREADS) {
// make API request
let name = context.params.event.data.options[0].value;
let result = await lib.discord.channels['@0.2.1'].threads.create({
channel_id: `${context.params.event.channel_id}`,
name: `${name}`,
auto_archive_duration: 1440,
type: 'GUILD_PUBLIC_THREAD',
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `**<@${context.params.event.member.user.id}> - thread successfully created!**`,
});
} else {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `**<@${context.params.event.member.user.id}> - You need the MANAGE_THREADS permission to use the Create Thread command**`,
});
}