What is the process for creating a multi-word argument?

Is there a way to create multi-word arguments, such as reasons for bans or mutes? Currently, I am using args[2], args[3], args[4], args[5]... but this approach is limited and if nothing is written in those arguments, it will display "undefined". If you know how to achieve this, I would greatly appreciate your answer. :)

const { ReactionCollector } = require("discord.js");

module.exports = {
    name: 'ban',
    description: "Temporarily bans a member.",
    async execute(message, args, Discord, client, chalk, ms){
        await message.channel.messages.fetch({limit: 1}).then(messages =>{
            message.channel.bulkDelete(messages);
        });

        const channelId = client.channels.cache.get('802649418087530537');
        const author = message.author;
        const userName = message.mentions.users.first();
        
        if(!message.member.permissions.has("BAN_MEMBERS")){
            message.reply('You do not have the necessary permissions!')
            .then(msg => {
                msg.delete({ timeout: 5000 })
            });
            return;
        } else if(!args[1]){
            message.reply('!ban <member> <duration> (<reason>)')
            .then(msg => {
                msg.delete({ timeout: 5000 })
            });
            console.log(chalk.red('[ERROR] Missing args[1]'));
            return;
        }
        if(userName){
            const userId = message.guild.members.cache.get(userName.id);
            const botId = '799652033509457940';
            userId.ban();
            
            const banEmbed = new Discord.MessageEmbed()
            .setColor('#a81919')
            .setTitle('Ban')
            .addFields(
                {name:'Member:', value:`${userId}`},
                {name:'Issued by:', value:`${author}`},
                {name:'Duration:', value:`${ms(ms(args[1]))}`},
                {name:'Reason:', value:`${args[2]}`},
            )
            .setTimestamp()
            channelId.send(banEmbed)

            setTimeout(function () {
                message.guild.members.unban(userId);

                const unbanEmbed = new Discord.MessageEmbed()
            .setColor('#25a819')
            .setTitle('Unban')
            .addFields(
                {name:'Member:', value:`${userId}`},
                {name:'Issued by:', value:`<@${botId}>`},
                {name:'Reason:', value:`Ban expired.`},
            )
            .setTimestamp()
            channelId.send(unbanEmbed)
            }, ms(args[1]));

            console.log(chalk.green(`[INFO] /ban/ ${userId.user.username}, ${ms(ms(args[1]))}`));
        }else{
            message.channel.send('You cannot ban this member');
            console.log(chalk.red(`[ERROR] /ban/ Can not find target`));
        }
    }
}

Answer №1

Assuming that the variable args have been properly initialized, you can easily accomplish this by using

args.join(" ");

to split each word with spaces.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Prevent onClick event in jQuery and extract parameters from a function call

We've been tasked with implementing a temporary solution to some code, so it might seem a bit silly at first. But please bear with us. The goal is to block the onclick method of an anchor tag, extract the parameters from the function call, and then u ...

Ways to create distance between repeated cards in a loop. My method involves utilizing ajax, jquery, and bootstrap

view image description here What is the best way to create some space between these closely aligned cards? .done((todos) => { todos.forEach(el => { console.log(el) $("#todo-list").append(` <d ...

What could be the reason for my onChange event not functioning properly?

The issue I'm experiencing involves my onchange event not properly copying the text from the current span to the hidden field. Any ideas on why this might be happening? Check out my code at this link. ...

Submitting data to an external PHP file using the JavaScript function $.post

Having issues with the PHP page function ajaxFunction(){ var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequ ...

Common reasons why you may encounter the error "Uncaught TypeError: $(...).DataTable is not a function"

I recently started working with DataTable.js, and when I tried to integrate it into my ASP.NET Core MVC 5.0 project, I encountered an error: Uncaught TypeError: $(...).DataTable is not a function After doing some research on Google, I discovered that this ...

Utilizing React to pass parent state to a child component becomes more complex when the parent state is derived from external classes and is subsequently modified. In this scenario,

I'm struggling to find the right way to articulate my issue in the title because it's quite specific to my current situation. Basically, I have two external classes structured like this: class Config { public level: number = 1; //this is a s ...

Integration of a QR code scanner on a WordPress website page

I'm in the process of setting up a QR code scanner on my Wordpress site or within a popup. The goal is for users to be able to scan a QR code when they visit the page/popup link. Specifically, the QR code will represent a WooCommerce product URL, and ...

Accessing data from a CD-ROM or DVD through a web browser

I am currently working on developing a web application for a friend that will enable users to simply click a button to upload all the content from the CD-ROM or DVD they have inserted directly to a server. It's not feasible to rely on the standard br ...

Using Dropzone.js to bypass the Browse dialog when uploading files in integration tests with php-webdriver

Currently, I am implementing dropzone.js in my project. I have a specific requirement where I need to manually add a file to the queue without triggering the file browser dialog box. The dropzone has been initialized on the element with the class .imageDro ...

Avoiding layout shift when a button is clicked in React JS

I am working on a Drawer example and following the instructions provided at https://mui.com/material-ui/react-drawer/ Everything is functioning as expected, but I am encountering an issue where my content shifts to the right when the drawer opens, and ret ...

Initiate an Ajax request solely for the elements currently visible on the screen

I am currently facing an issue that requires a solution. Within our template, there are multiple divs generated with the same classes. Each div contains a hidden input field with the ID of the linked target site. My task is to utilize this ID to make aja ...

Updating a global variable in Angular after making an HTTP call

I'm facing a challenge where I have a global variable that needs to be updated after an HTTP GET call. Once updated, I then need to pass this updated variable to another function. I'm struggling to figure out the best approach for achieving this. ...

Having trouble inputting text into the text area using Selenium WebDriver with C#

Here is the original code snippet: I am having trouble entering text in the text box below. Can you please help me figure out how to enter text in this text box? <td id="ctl00_cRight_ucSMS_redSMSBodyCenter" class="reContentCell" ...

How come my web page is not displaying the guages from guage.js?

I am utilizing guage.js to create a graph based on this Fiddle. However, upon adding the same code to my website, the rendering does not appear as expected: https://i.sstatic.net/fIkQr.png Upon inspecting in Chrome developer tools, I noticed that the ele ...

How to Customize the Navbar Position in Bootstrap 3 when the Brand/Logo is Collapsed

I am currently in the process of creating my first website and experimenting with the Bootstrap 3 framework. The navbar I have selected is designed to adjust based on screen size, collapsing into a small button for use on tablets and mobile devices. Howe ...

Rendering an array of objects in Three JS

I am encountering an error while trying to render an array of objects in a three.js scene. The error message from three.js reads as follows: three.module.js:8589 Uncaught TypeError: Cannot read property 'center' of undefined at Sphere.copy (thr ...

Can regex matching characters be made easier to understand?

I am working on creating an ECMAScript (JavaScript) flavored regex to evaluate the complexity of my password based on specific criteria: Characters Used Password Strength Length ABC abc 123 #$& WEAK ... 1 x ...

Retrieve data points from ol.layer.Vector using OpenLayers 4

Having recently started using OpenLayers, I find myself in a state of confusion. I'm attempting to retrieve all features from a kml vector layer, but have been unsuccessful thus far. It perplexes me as to what mistake I might be making. Below is the ...

Best practices for managing useEffect dependencies on page reload

I have a simple blog with articles. When a user clicks the edit button, a form is supposed to be filled with the article's data - title, description, body, and tags. I am using the useEffect hook to retrieve the data and fill the form based on the "id ...

How can we redirect using an OnClick event handler in React.js?

I've been doing a lot of reading and trying to understand how to redirect using withRouter in React. However, I came across some information stating that when onClick occurs, the page should be redirected to a specific link. Additionally, I learned th ...