Is there a way to troubleshoot and improve my Discord bot's kick functionality?

I'm having an issue with my code. When I type in the command "exp kick @user being toxic", it doesn't do anything. It seems to be ignoring my command. Here is the code snippet that I'm using:

client.on("message", message => {
    var command = message.content.toLowerCase().split(" ")[0];
    if(command == prefix + "kick"){
        if(message.guild.member(message.author).hasPermission("KICK_MEMBERS")) {
            return message.channel.send("Please Check Your Permissions");
        }
        if(!message.guild.member(client.user).hasPermission("KICK_MEMBERS")) {
            return message.channel.send("Please Check My Permissions");
        }
        const user = message.mentions.users.first();
        if(!user) {
            return message.channel.send("I can't find this user!");
        }
        const reason = message.content.split(" ").slice(2).join(" ");
        if(!reason) {
            return message.channel.send("Please state the reason for the kick!");
        }
        if(message.guild.member(user).kickable) {
            return message.channel.send("This user seems to have permissions that are preventing the kick.");
        }
        message.guild.member(user).kick({reason: reason});
        return message.channel.send(`Kicked the user \`${user.tag}\``);
    }
})

Answer №1

You've got quite a lot of typos in your code, but don't worry, I fixed them and now everything should be working as it should. Below are the sections where you made mistakes, followed by the corrections I made. I had to tidy it up a bit because it was quite difficult to read.


client.on("message", message => {
    var command = message.content.toLowerCase().split("")[0];
    if(command == prefix + "kick") {
        if(!message.guild.member(message.author).hasPermission("KICK_MEMBERS"))
            return message.channel.send("Please Check Your Permissions");
        if(!message.guild.member(client.user).hasPermission("KICK_MEMBERS"))
            return message.channel.send("Please Check My Permissions");
        const user = message.mentions.user.first();
        if(!user) return message.channel.send("I can't find this user!");
        const reason = message.content.split(" ").slice(2).join(" ");
        if(!reason) return message.channel.send("Please state the reason for kick!");
        if(!message.guild.member(user).kickable) return message.channel.send("This user seems to have permissions which got in the way");
        message.guild.member(user).kick({reason: reason});
        return message.channel.send("Kicked the filthy member `@"+user.tag+"` ");
    }
})

client.on("message", message => {
  var command = message.toLowerCase().split(" ")[0];
  if(command == prefix + "kick") {
    const user = message.mentions.users.first();
    const reason = message.content.split(" ").slice(2).join(" ");
    if(!message.guild.member(message.author).hasPermission("KICK_MEMBERS")) return message.channel.send("Please Check Your Permissions");
    if(!message.guild.member(client.user).hasPermission("KICK_MEMBERS")) return message.channel.send("Please Check My Permissions");
    if (!user) return message.channel.send("I can't find this user!");
    if (!reason) return message.channel.send("Please state the reason for kick!");
    if (!message.guild.member(user).kickable) return message.channel.send("This user seems to have permissions which got in the way");
    message.guild.member(user).kick({reason: reason});
    return message.channel.send("Kicked the filthy member <@" + user.id + ">");
  }
})

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

Automatic Slideshow

I am trying to implement autoplay in my slider, but I am having trouble figuring out how to do it. The slider itself is working fine, but I know that I need to use an interval for the autoplay feature. If anyone could provide some assistance on how to ac ...

Make sure the "Treat labels as text" option is set to true when creating a chart in a Google spreadsheet using a script

I am currently working on a script using Google Spreadsheet Apps Script interface and I need to set the marker for 'Treat labels as text' to true. Despite searching through App Script documentation, I couldn't find any specific mention of t ...

Utilizing commas in JavaScript

Hi everyone, I'm having an issue with printing the message "Invalid password, Must Contain:". The problem I'm facing is that when I write the code in JavaScript, the comma is being interpreted as an operator instead of a regular English comma. Th ...

The timer will automatically refresh when the page is refreshed

Currently, I am encountering an issue while working on a quiz application in PHP. The problem arises when users start the test and the timer is running correctly. However, when users move to the second question, the timer resets again. Below is the code sn ...

Create a password variable while typing

Looking to avoid interference from browsers with autocomplete and password suggestions while maintaining the show/hide letters feature. The goal is to keep the password stored as a variable, regardless of whether the characters are shown or hidden. The is ...

What are the similarities between using the map function in AngularJS and the $map function in jQuery?

I am currently in the process of migrating jQuery code to AngularJS. I have encountered some instances where the map function is used in jQuery, and I need to replicate the same functionality in AngularJS. Below is the code snippet that demonstrates this. ...

A guide on invoking a web method from an aspx.vb page in VB.net

My goal is to call a WebMethod from my aspx.vb file. Below is the syntax of my WebMethod located in Default.aspx.vb: <System.Web.Services.WebMethod()> _ <ScriptMethod(UseHttpGet:=True, ResponseFormat=ResponseFormat.Json)> _ Public Shared Funct ...

What is the proper usage of a jwt token?

I'm completely new to this and I've dedicated all my time to figuring out how to create a mechanism for generating JWT tokens. These tokens are necessary for identifying the 'signed in' status of users. I opted for FastAPI, and after s ...

Rendering HTML with jQuery using AJAX: Step-by-step guide

Within my webpage, I have implemented a select box that contains a list of various books. The purpose of this select box is to allow the user to choose a book and then click a submit button in order to view the chapters of that book on a separate page. Ho ...

I recently incorporated Puppeteer along with its necessary dependencies onto Heroku, and as a result, pushing my small app to Heroku now takes approximately 5 to 6 minutes

I am currently using Puppeteer to create a PDF from an HTML page. I installed the npm package by running the following command: npm i puppeteer However, when I deployed to Heroku, I encountered an error: Error while loading shared libraries: libnss3.s ...

Having trouble with Vue's $route.push method not working when invoked from a method?

I am currently in the process of creating a search bar for my application using the vue-bootstrap-typeahead autocomplete library. For those unfamiliar, when an option is selected from the suggestions list, it triggers the @hit event which passes the result ...

Transform an object into an array using JavaScript with the help of Lodash, Azure Functions, and Azure Logic Apps

To achieve the desired result of extracting JSON from a proprietary content management system, transforming it into a CSV, and depositing that CSV in an Office 365 shared drive, a combination of Azure Function and Azure Logic App is utilized. The Node/Java ...

async.auto: halt the entire sequence upon encountering the initial error

My understanding was that the behavior of async.auto was such that if one task returned an error (err), the global callback would be triggered with this error and no further tasks would execute. It seemed logical - why continue executing tasks when an erro ...

Tips for managing unfinished transactions through Stripe

I have successfully set up a checkout session with Stripe and included a cancel_url as per the documentation. However, I am facing an issue where the cancel_url is only triggered when the user clicks the back button provided by Stripe. What I want to achie ...

An error of TypeError is being encountered in AngularJS

Hello, I am new to creating mobile apps with Ionic and Angular. Currently, I have a simple login form and a corresponding login button that triggers a controller. Here is the code snippet for the controller: angular.module('starter.controllers', ...

What is the best way to navigate a carousel containing images or divs using arrow keys while maintaining focus?

Recently, I have been exploring the Ant Carousel component which can be found at https://ant.design/components/carousel/. The Carousel is enclosed within a Modal and contains multiple child div elements. Initially, the arrow keys for navigation do not work ...

Utilizing a foundational element to automatically unsubscribe from multiple observable subscriptions

Within our Angular application, we have implemented a unique concept using a Base Component to manage observable subscriptions throughout the entire app. When a component subscribes to an observable, it must extend the Base Component. This approach ensures ...

Tips for implementing an HTML modal with AngularJS binding for a pop up effect

As a beginner in AngularJS, I am facing a challenge. I have an HTML page that I want to display as a pop-up in another HTML page (both pages have content loaded from controllers). Using the router works fine for moving between pages, but now I want the s ...

Implementing a node.js application deployment with pm2 to ensure zero downtime

While there are countless tutorials on developing chat applications using socket.io and node.js, the event-driven advantage of Node is undeniable for building chat apps. However, a recent thought crossed my mind - how can I ensure the sustainability of my ...

Instructions on dynamically positioning a collection of div elements at the center of a webpage container

I am looking to create a set of divs that are centered on the page and adjust in size according to the length of the username. .Container1 { display: table; width: 100%; padding:0; margin:0; -webkit-box-sizing: border-box; -moz-box-sizing: bor ...