Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JS How can I modify this to make read brackets as one arg and still make non-brackets work? For example: !poll [test,1,2,3,4] or !gif kitten

JS How can I modify this to make read brackets as one arg and still make non-brackets work?

For example: !poll [test,1,2,3,4] or !gif kitten or !someother [a][1234] (two args)

const gif = require("./commands/gif.js");

const poll = require("./commands/poll.js");

const commands = { poll, gif };

module.exports = async function (msg) {

// if (msg.channel.id == "") {}

let tokens = msg.content.split(" ");

let command = tokens.shift();

if (command.charAt(0) === "!") {

command = command.substring(1);

commands[command](msg, tokens);

}

};

________________________________________

let totalOptions = 0;

var reaction_numbers = [

"\u0030\u20E3",

"\u0031\u20E3",

"\u0032\u20E3",

"\u0033\u20E3",

"\u0034\u20E3",

"\u0035\u20E3",

"\u0036\u20E3",

"\u0037\u20E3",

"\u0038\u20E3",

"\u0039\u20E3",

];

module.exports = async (msg, args) => {

num_matches = msg.content.match(/[,]/gi).length;

if (num_matches == 2) {

msg.channel.send("You need at least one choice");

} else {

let choices = "";

statement = args[0].split(",");

totalOptions = statement.length;

for (let i = 1; i < statement.length; i++) {

choices += "Option" + i + ": " + statement[i] + " ";

}

msg.channel.send("Question: " + statement[0] + " " + choices);

console.log(totalOptions);

msg.channel

.fetchMessages({ limit: 1 })

.then(async (messages) => {

let lastMessage = messages.first();

for (let i = 1; i < totalOptions; i++) {

try {

await lastMessage.react(reaction_numbers[i]);

} catch (error) {

console.error("One of the emojis failed to react.");

}

}

})

.catch(console.error);

}

msg.channel.send(num_matches);

};

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions