Prefix command that creates a new channel only visible to the author, with a built in cooldown. Use with "!privatechannel".
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let message = `${context.params.event.content}`;
let userCooldownKey = `${context.params.event.author.id}cooldown`;
if (message.startsWith(`!privatechannel`)) {
let cooldown = await lib.utils.kv['@0.1.16'].get({
key: userCooldownKey,
});
if (cooldown) {
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `You are currently on cooldown. Please wait to try this command again.`,
});
} else {
await lib.utils.kv['@0.1.16'].set({
key: userCooldownKey,
value: true,
ttl: 120,
});
await lib.discord.guilds['@0.1.0'].channels.create({
guild_id: `${context.params.event.guild_id}`,
name: `${context.params.event.author.username}-${new Date().toISOString()}`,
topic: `Private channel for ${context.params.event.author.username}`,
permission_overwrites: [
{
id: `${context.params.event.guild_id}`,
type: 0,
deny: `${1 << 10}`,
},
{
id: `${context.params.event.author.id}`,
type: 1,
allow: `${1 << 10}`,
},
],
});
}
}