Create a suggestion channel for everyone to propose and vote! And create a discussion thread at the polling desk!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
//You can set in "Environment Variables"
let suggestions_channel = `${process.env.suggestion_channel}`;
// function of sleep
let sleep = async (ms) => {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
};
//
//main code
if (context.params.event.channel_id == suggestions_channel) {
var calc = require('ez-calculator');
const message = context.params.event;
let num = await lib.utils.kv['@0.1.16'].get({
key: `Suggestions_num_${process.env.key}`,
defaultValue: 1,
});
//channel of suggestion
await sleep(1500);
await lib.discord.channels['@0.2.0'].messages.destroy({
channel_id: context.params.event.channel_id,
message_id: context.params.event.id,
});
const suggestions = await lib.discord.channels['@0.2.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
//allowed_mentions: {
// replied_user: false,
// parse: [roles],
// roles: ['865176556607242251'],
//},
embeds: [
{
type: 'rich',
title: `#${num} Suggestion:`,
description: '',
color: 0xb21818,
fields: [
{
name: `Content:`,
value: `${context.params.event.content}`,
},
],
footer: {
text: ` | ${context.params.event.author.username}#${context.params.event.author.discriminator}`,
icon_url: `https://cdn.discordapp.com/avatars/${message.author.id}/${message.author.avatar}`,
},
},
],
});
for (let emoji of ['⬆', '⬇']) {
await lib.discord.channels['@0.2.0'].messages.reactions.create({
emoji,
message_id: suggestions.id,
channel_id: suggestions.channel_id,
});
}
let threads = await lib.discord.channels['@0.2.0'].threads.create({
channel_id: `${context.params.event.channel_id}`, // required
name: `Suggestion ${num} | thread`, // required
auto_archive_duration: 1440,
message_id: suggestions.id,
type: 'GUILD_PUBLIC_THREAD',
});
let thread = await lib.discord.channels['@0.2.0'].threads.members.create({
thread_id: `${threads.id}`,
user_id: `${context.params.event.author.id}`,
});
await lib.discord.channels['@0.2.0'].threads.update({
thread_id: `${threads.id}`,
rate_limit_per_user: 3,
});
await lib.discord.channels['@0.2.0'].messages.create({
channel_id: threads.id,
content: `Questions about ${context.params.event.content} can be discussed in this area!`,
});
var result = calc.calculate(`${num}+1`);
await lib.utils.kv['@0.1.16'].set({
key: `Suggestions_num_${process.env.key}`,
value: result,
});
await sleep(1000);
}
//console.log(`none`);