This will create a message with dropdown menus allowing to select channels of your server, useful for setting lockdown or channel whitelist commands. This is only an example, this suppots up to 100 channels. You have to code the end button which has the ID of "channel_confirm", I hope this helps on your adventure! To test it: 1) Input channelId and guildId 2) Click RUN
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
/*
PLEASE READ
This will create a message with dropdown menus allowing to select channels
of your server, useful for setting lockdown or channel whitelist commands
This is only an example, this suppots up to 100 channels.
You have to code the end button which has the ID of "channel_confirm",
I hope this helps on your adventure!
To test it:
1. Input channelId and guildId
2. Click RUN
*/
let guildId = `881286866610061333`;
let channelId = `931482609379319838`;
function splitArrayIntoChunksOfLen(arr, len) {
var chunks = [],
i = 0,
n = arr.length;
while (i < n) {
chunks.push(arr.slice(i, (i += len)));
}
return chunks;
}
let channels = await lib.discord.guilds['@0.2.4'].channels.list({
guild_id: `${guildId}`,
});
console.log(channels.length);
let channelChunks = splitArrayIntoChunksOfLen(channels, 25);
console.log(channelChunks[0].length);
console.log(channelChunks[1] ? `${channelChunks[1].length}` : `n/a`);
let options_row_1 = [];
for (let i = 0; i < channelChunks[0].length; i++) {
let currentOption = {
label: `${channelChunks[0][i].name}`,
value: `${channelChunks[0][i].id}`,
description: ``,
default: false,
};
options_row_1 = options_row_1.concat(currentOption);
}
let options_row_2 = [];
if (channelChunks[1]) {
console.log(`1`);
for (let i = 0; i < channelChunks[1].length; i++) {
let currentOption = {
label: `${channelChunks[1][i].name}`,
value: `${channelChunks[1][i].id}`,
description: ``,
default: false,
};
options_row_2 = options_row_2.concat(currentOption);
}
}
let options_row_3 = [];
if (channelChunks[2]) {
for (let i = 0; i < channelChunks[2].length; i++) {
let currentOption = {
label: `${channelChunks[2][i].name}`,
value: `${channelChunks[2][i].id}`,
description: ``,
default: false,
};
options_row_3 = options_row_3.concat(currentOption);
}
}
let options_row_4 = [];
if (channelChunks[3]) {
for (let i = 0; i < channelChunks[3].length; i++) {
let currentOption = {
label: `${channelChunks[3][i].name}`,
value: `${channelChunks[3][i].id}`,
description: ``,
default: false,
};
options_row_4 = options_row_4.concat(currentOption);
}
}
let components = [];
let components1 = [
{
custom_id: `channels_row_1`,
placeholder: `Select Channels`,
options: options_row_1,
min_values: 0,
max_values: channelChunks[0].length,
type: 3,
},
];
components = components.concat({
type: 1,
components: components1,
});
if (channelChunks[1]) {
components2 = [
{
custom_id: `channels_row_2`,
placeholder: `Select Channels`,
options: options_row_2,
min_values: 0,
max_values: channelChunks[1].length,
type: 3,
},
];
components = components.concat({
type: 1,
components: components2,
});
}
if (channelChunks[2]) {
components3 = [
{
custom_id: `channels_row_3`,
placeholder: `Select Channels`,
options: options_row_3,
min_values: 0,
max_values: channelChunks[2].length,
type: 3,
},
];
components = components.concat({
type: 1,
components: components3,
});
}
if (channelChunks[3]) {
components4 = [
{
custom_id: `channels_row_4`,
placeholder: `Select Channels`,
options: options_row_4,
min_values: 0,
max_values: channelChunks[3].length,
type: 3,
},
];
components = components.concat({
type: 1,
components: components4,
});
}
let button = [
{
style: 1,
label: `Confirm`,
custom_id: `channel_confirm`,
disabled: false,
type: 2,
},
];
components = components.concat({
type: 1,
components: button,
});
console.log(components);
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${channelId}`,
content: '',
embeds: [
{
type: 'rich',
title: `Channels`,
description: `Select channels below and then click "Confirm"`,
color: 0x00ffff,
},
],
components: components,
});