Tips on getting the bot to react to a single "event" mentioned in the sentence, without multiple occurrences

Things are a bit complicated, but here's an example to illustrate:

I've set up this event:

client.on('message', async message => { 
if (message.content.toLowerCase().includes("megumin"))
 {
    message.channel.send("What's up?");
}
});

However, I also have another event declared:

client.on('message', async message => { 
if (message.content.toLowerCase().includes("thanks megumin"))
 {
    message.channel.send("We are welcome UwU");
}
});

The issue arises when I type "thanks megumin" in the chat, and the bot triggers both events! What I actually want is for it to only respond to "thanks megumin" specifically, without reacting to the mention of "megumin" within the sentence. Can anyone help me with this?

Thank you @Levi_OP!

Answer №1

It's more efficient to consolidate two client.on functions into one.

client.on('message', async message => { 
  if (message.content.toLowerCase().includes("thanks megumin")) {
    message.channel.send("You're welcome!");
  } else if (message.content.toLowerCase().includes("megumin")) {
      message.channel.send("Hey there!");
  }
});

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

What could be causing my HTML button to malfunction when attempting to navigate to a different section of the webpage?

Just starting out and developing my website. My hosting provider is IPage, but I'm running into an issue. When I click on a button to switch to another section of the site, it's not working as expected. Here's the code snippet: <button on ...

Feeling lost on how to implement JSON in C#?

When it comes to using C# with JSON, the common answer is always "use JSON.NET", but that's not the solution I'm searching for. The issue lies in the fact that JSON.NET, based on my research, appears to be just a more efficient version of the Da ...

Having trouble with playing audio from an array in Javascript

I've been working on creating a Drum Kit website. My approach involves using an array to hold all the sound files, and using a loop to call the play() function. However, I encountered an issue when trying to load the sounds - the debug console showed: ...

The function $.post(...) is failing to detect the JSON content in the

I am attempting to send a POST request to the server using the following code: var body = { PatientAgeFilter: { CompareOperator: parseInt(self.patientAge()), MoreThanVal: { AgeSpecifier: 0, AgeValue: parseInt(se ...

Is there an efficient method for transferring .env data to HTML without using templating when working with nodejs and expressjs?

How can I securely make an AJAX request in my html page to Node to retrieve process.env without using templating, considering the need for passwords and keys in the future? client-side // source.html $.get( "/env", function( data ) {console.log(data) ...

Issue with .env file access token: Successfully working for one API in Next.js, but failing for

I am utilizing two different APIs, WordsAPI and Spotify API. Each API requires an access token or key which I have stored in a secure .env file. I have successfully fetched data from WordsAPI using the same method in getStaticProps, but I am facing issues ...

Improving a lengthy TypeScript function through refactoring

Currently, I have this function that I am refactoring with the goal of making it more concise. For instance, by using a generic function. setSelectedSearchOptions(optionLabel: string) { //this.filterSection.reset(); this.selectedOption = optionLa ...

How to import an HTML file using TypeScript

I need to load an html file located in the same directory as the typescript file and return it from the function. public ...(... ) : angular.IHttpPromise<string> { ... return $http({ method: 'GET', url: &apos ...

Drawing a line beneath the mouse's center using JavaScript

Struggling with my JavaScript drawing tool, particularly the draw() function. The line is consistently off-center below the mouse cursor. How do I fix this issue? My aim is to have the line always follow the center of the mouse as it moves. Could someone c ...

Establishing global date restrictions for the DatePicker component in Angular 8 using TypeScript across the entire application

I am currently learning Angular 8 and I am looking to globally set the minimum and maximum dates for a datepicker in my application. I would like to accomplish this by using format-datepicker.ts. Any suggestions on how I can achieve this? Min date: Jan 1, ...

The second JSP page fails to load following an AJAX POST request

The following code snippet is found in page1.jsp. $.ajax({ type: "post", url: "page2.jsp", data: newdata, success:function(msg){ return msg; } ...

Cross domain Ajax POST requests using CodeIgniter and AjaxBy utilizing CodeIgn

Initially, I would like to clarify ... I own two domains: www.one.com and www.two.com The first domain www.one.com has a form input below <div class="hidden cswrap2"> <h3>Edit Data Mustahik</h3> <div class="cscontent"> ...

Unexpected behavior of NewtonSoft json.Net in Powershell Core

Displayed below is a PowerShell function designed to convert a PS object to a NS json.Net object. function ConvertTo-NSJson ( $psObject ) { $json = $psObject | ConvertTo-Json -Compress -Depth 10 $nsJson = [Newtonsoft.Json.Linq.JObject]::Parse( $jso ...

When you click on the submit button, it triggers the associated event

I have multiple text input fields where pressing the enter key should move focus to the next field. After reaching the last text input, I want the focus to be on the submit button without triggering its click event until the user presses enter again. The c ...

Is it possible to maintain HTML, JS, and CSS files as separate entities when developing Vue.js components, similar to how it is

Is it possible to maintain separate HTML, JS, and CSS files while creating Vue.js components? I recently read the "Why Vue.js doesn't support templateURL" article which discusses this topic. "Proper modularization is a necessity if you want to bu ...

Tips for properly sending an array containing objects in JSON format using Swift for iOS development

As a beginner, I am trying to grasp the concept of sending an array with objects. Does the server recognize arrays like Int, Strings, or Booleans? Do I need to convert the array into a string for JSON data? There seems to be something I'm missing. va ...

Guidelines for Naming in Azure Policy

I am facing an issue with the Azure Policy I am working on. My goal is to enforce a naming policy that prevents the creation of a resource group with certain names. { "properties": { "mode": "All", "di ...

An error has occurred within the Discord client while processing the on_ready event, and

I encountered an error message and need assistance with resolving it. () Below is the code snippet: import discord import requests from bs4 import BeautifulSoup client = discord.Client(intents=discord.Intents.default()) def get_latest_article(): url = ...

Disabling the scrollbar in Selenium screenshots

When using Chromedriver to capture screenshots of webpages, my code effectively does the job. However, I am now facing an issue with removing the unsightly scrollbars from the image. Is it feasible to inject CSS into the webpage in order to achieve this? W ...

I am looking to remove the target attribute from an anchor tag if it does not have a value assigned

To ensure W3C validation, I must remove the target attribute from all anchors where the target value is null. Here is the code snippet inside the body: <div> <a href="#" target="">home empty</a> <a href="#" target="blank">home&l ...