Is there a way to adjust the code so that the bot can scan an entire discord message for certain phrases and mention specific roles in its reply?

I've been working on developing a Discord bot that will react whenever it detects the mention of 'Tier 5 Egg' in any part of a message.

bot.on("message", message => {
  if(message.content === 'Tier 5 Egg') {
    message.channel.send('A Tier 5 Egg has appeared for @role1 and @role2');
  }
});

My goal is for the bot to send a message and tag two specific roles when it reacts. I tried using "@" followed by their role ID, but it displays as plain text. I'm also struggling with getting the bot to recognize the entire message for that specific phrase.

Answer №1

If you refer to the details mentioned in the Documentation, once you have obtained the role, all you need to do is combine it with the message string and it will automatically mention the role. You can attempt something similar to this:

bot.on("message", message => {
  if(message.content.indexOf('Tier 5 Egg') > -1) {
    let role1 = message.channel.guild.roles.find('name', 'role1Name');
    let role2 = message.channel.guild.roles.find('name', 'role1Name');
    message.channel.send(`A Tier 5 Egg has appeared in ${role1} ${role2}`);
  }
});

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

Tips for positioning divs on top of an image with Twitter Bootstrap

I'm having an issue with displaying an image and dividing it using bootstrap div columns. The problem is that the image is overlapping the divs, making it impossible to click or attach jQuery events to it. Here is the code I am currently using: #view ...

Issue with locating element in iframe using Selenium and Chromedriver: Element not found

Having some trouble working with Selenium/Chromedriver via Protractor. I try to switch to an iframe, wait for the contents to load, and then manipulate elements inside it. However, the program doesn't seem to recognize when the content has loaded. br ...

What is the significance of having 8 pending specs in E2E Protractor tests on Firefox?

Each time I execute my tests, the following results are displayed: There were 11 specs tested with 0 failures and there are 8 pending specs. The test execution took 56.861 seconds to complete. [launcher] There are no instances of WebDriver still running ...

Tips on creating an onclick function in javaScript and linking it to innerHTML

let a = 10; let b = 15; document.getElementById("text").innerHTML = '<div onclick=\'testing("'a + '","' + b + '") > text </div>'; Welcome, I am new to this ...

Add more JSON entries to the data submission in Express

Purpose: My goal is to ensure that the JSON data I submit is formatted correctly when it arrives in the JSON file, regardless of the number of entries I submit. Challenge: Currently, the data I submit does not append properly in the JSON file. It appear ...

Exploring the syntax of ReactJS state management with setState

Trying to wrap my head around the following syntax in my React app. I am looking to understand how the code inside setState() works. this.getSomePromise().then( // resolve callback function someImg => this.setState(prevState => ( ...

Discovering a specific value by locating a string in an array nested inside an object

Here is an example object that I need help searching: data = [ { type: "fruit", basket: ["apple", "pear", "orange"] }, { type: "vegetable", basket: ["carrot", "potato"] } ]; I am trying to find the item 'potato' and retu ...

Utilize Discord.js v13 to stream audio directly from a specified URL

Can anyone help me figure out how to play audio from a URL using discord.js v13? I attempted this code but it's not working as expected. const connection = joinVoiceChannel({ channelId: voiceChannel.id, guildId: message.guild.id, adapterCreator ...

Using Java to write scripts - executing JavaScript from a server-side Java class file in version 1.5

I receive three different types of GET requests from a mobile device to a class file on my web application. Since the mobile device does not provide any cookies, the log file only captures: in.ter.nal.ip ser.ver.i.p:port 2009-06-05 09:14:44 GET / ...

Having trouble with the ng-class syntax?

I've been diving into the world of Angular.js and came across this code snippet: <button ng-class="{'btn pull-left', duplicatesInList === true ? 'btn-warning': 'btn-success'}" id="saveScoreButton" type="button" ng-c ...

Tips for maintaining a variable's persistence through Heroku dyno/server restarts and fresh deployments

I need to find a way to persist the values in an array through dyno restarts and code deployments on my Node.js server. The issue I am facing is that every time the server restarts, the 'arrayWithValues' array gets reset to empty. Below is the se ...

IconButton function in ReactJS malfunctioning specifically in Firefox browser

There seems to be an issue with the click function of IconButton from Material UI not working in any version of FireFox. Below is the code snippet in question: <div className='floating-button visible-xs'> <IconButton touch={true} tool ...

How to fix jQuery animate queue issue so animations run at the same time

Previously, I successfully used the jQuery queue modifier for simultaneous animations. However, this time around, I am facing difficulties in getting it to work. You can view the issue on the following page: . When you click on "notifications" at the top ...

JavaScript: Creating a new entry in a key-value paired array

I am in the process of creating a dynamic menu for use with jQuery contextMenu. I have encountered an issue when trying to add a new element, as it keeps showing the error message 'undefined is not a function'. The menu functions correctly witho ...

What is the best way to alter the background-color of an element that is contained within a GatsbyJS component, depending on the specific page where the component is being utilized?

As a first-time GatsbyJS website builder, I am working on creating reusable components for my site. One of these components is the footer, and I have already structured it. Now, I have a dilemma - I want to change the color of a specific <div> within ...

What could be causing the return of undefined upon execution?

function updateTitle(title) { title = "updated title"; } var currentTitle = "original title"; currentTitle = updateTitle(currentTitle); console.log(currentTitle) I'm just starting to learn JavaScript and I'm curious about why this code behav ...

Switch between GeoJSON layers by using an HTML button within Mapbox GL JS, instead of relying on traditional links

I am currently developing a web map that requires toggling two GeoJSON layers on and off. In the past, I used Mapbox JS to accomplish this task by adding and removing layers with a custom HTML button click. However, I am facing some challenges in achieving ...

JavaScript framework enabling front-end communication with RESTful APIs

I am searching for a lightweight javascript framework to build a client-side web application that will interact with the server via a REST API. I initially considered using react.js, but my team members rejected the idea because it lacks templating. Angul ...

Stopping setTimeout when leaving the current page: Is it possible?

Good evening, I am looking for advice on how to cancel a setTimeout function when a user navigates to other pages (for example, by clicking other links or pressing the back button in the browser, but not by changing tabs). I have attempted to use the windo ...

Implementing a PHP button update functionality sans utilizing an HTML form

I need a way to update my database with just a click of a button, without using any forms or POST requests. Most examples I've seen involve updating through forms and the $_POST method. Is there a simpler way to update the database by directly click ...