Turns a list of strings into an array, ready to be copypasted into your code. Has tagscript option too.
/**
* LIST-TO-ARRAY DISCORD SLASH COMMAND
* by vibrantium#0953
* * Warning:
* 1. Make sure this is a slash command titled "turnarray"
* 2. Make sure it has a REQUIRED string option titled "string" to input your list
* 3. Your list must be separated by an enter or else you'll get an error
* 4. Make sure it has a REQUIRED string option titled "format" for you to select the output style
* 5. You have TWO format choices: "autocode ready" & "tagscript ready"
* */
// DEPENDENCIES - Do not modify & do NOT DELETE
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
/** This is how your slash command registration code should look like in the slash command builder:
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
await lib.discord.commands['@0.0.0'].create({
"guild_id": "YOUR-GUILD-ID", // modify with your own guild ID serial number
"name": "turnarray",
"description": "Make a list of words into array-ready format",
"options": [
{
"type": 3,
"name": "string",
"description": "Input the list of string you want to turn into array",
"required": true
},
{
"type": 3,
"name": "format",
"description": "Style of array",
"choices": [
{
"name": "autocode ready",
"value": "1"
},
{
"name": "tagscript ready",
"value": "2"
}
],
"required": true
}
]
}); // end of slash command registration
// If you've registed the slash command manually: delete everything before this EXCEPT dependencies (lib)
*/
// Reply to the slash command invocation
await lib.discord.interactions['@1.0.1'].responses.create({
token: context.params.event.token,
response_type: 'DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE',
});
// I like to use try-catch just so the bot won't type forever if something goes wrong
try {
// teaching the bot to detect options
let l = context.params.event.data.options.find(
(option) => option.name === 'string'
).value;
let f = context.params.event.data.options.find(
(option) => option.name === 'format'
).value;
// variable declarations
var ls;
var x;
// Uneven space & comma cleaner just in case
if (l.includes(', ')) {
ls = l.replace(', ', ',').split(',');
} else {
ls = l.replace(/\s+/g, ',').split(',');
}
console.log(
`For debugging: this is the list item(s) separated only by a comma`
);
console.log(ls);
console.log(`ls.length is ${ls.length}`);
let list = new Array();
let a = 0;
do {
let item = ls[a].toString();
// Format the item to the selected format option
if (f === '1') {
list.push(`'${item}'`);
} else {
list.push(item);
}
a++;
} while (a < ls.length); // end of do // end of while
// final presentation
var final;
if (f === '2') {
final = list.toString().replace(/,/g, '~');
} // you can change the separator to comma or anything else
else {
final = `[${list.toString()}]`;
}
// Send result to channel
await lib.discord.interactions['@1.0.1'].followups.create({
token: context.params.event.token,
channel_id: context.params.event.channel_id,
content: `\`\`\`${final}\`\`\``,
}); // end message sending
} catch (e) {
// end of try
// start of error handling
console.log(e);
// Start of bot sending error message to channel
await lib.discord.interactions['@1.0.1'].followups.create({
token: context.params.event.token,
channel_id: context.params.event.channel_id,
content: `**__Error__!**`, // Feel free to modify your own error message
}); // end of error message sending
} // end of everything