How to check if a certain user was mentioned [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to check if a user has been mentioned (#user) in a message. This is what i currently have:
} if (message.content.includes('<#796406791323516999>')) {
message.channel.bulkDelete(1);
message.channel.send('User mention was detected')
}
(This is wrapped in a client.on detecting when a message is sent)
What am i doing wrong here?

You can use Mentions#members#has using the member's id to check if there were any mentions, and if the member was one of the mentions.
const mentions = message.mentions.members;
if (!mentions) return message.channel.send('No Mentions Error Message.');
if (mentions.has('796406791323516999')) {
message.channel.bulkDelete(1);
message.channel.send('User mention was detected');
}

Related

How can I detect if user has successfully alerted a thing (I'm making an XSS game) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The page just echoes the user input using GET. I have no idea on what concept to apply to detect if the user has alerted something
The easiest approach would probably be to replace the alert method with your own.
const log = [];
alert = function(alert) {
return (value) => {
log.push(value);
alert(value);
};
}(alert);
alert("Hello!");
console.log(log);

How to pass index value and get name from array response angular [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
onRowClick function, i am getting index id.
Try this below :
onRowClick($event) {
const indexid= $event;
this.tagPolicesArray['records'].map(function(item, index){
if(index == indexid){
console.log(item['name']); ----------------> Here you will get your required name
}
});
}

Best approach to Logging in javascript [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to console.log but then turn it off in production without deleting the logs statements.
What are other logging levels and how can i utilise them?
What benefits do logging libraries such as log4js offer?
Place this code in your webpage
if(window.location.hostname=="example.com"){
console.log = function(){
return;
}
}
What it will do is, if the domain name is example.com it will override the console.log functionality and it will print nothing in console.
This way it will also work in your local environment.
var myAPI={isLogged:false};
(function(api){
if(window.location.hostname=="dev.example.com"){
myAPI.isLogged=true;
}
api.log=function(msg,level){
if(!level){level='log'} //can be : warn, info, error, debug or log
if( myAPI.isLogged){
console[level](msg);
}
};
})(myAPI) ;
Then , use :
myAPI.log(new Date()+' This is security check ');
or
myAPI.log(new Date()+' Wrong password ','error');

Show results of multiple prompt boxes using Javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to make multiple prompt boxes and sort their input alphabetically and then show on screen using JavaScript ?
Thanks
Sequentially
if you are talking about the almost obsolete native javascrtipt function prompt() then:
var array=[];questions=['A?','B?','C?'],current=0;
function q(question){
array.push(prompt(question,'write here')+' question number:'+current);
if(current<questions.length){
next()
}else{
array.sort()// needs a proper sort function
alert(array.join("\n"));
};
}
function next(){
q(questions[current++]);
}
next();
Demo
http://jsfiddle.net/c7GnX/

Validation on special codes [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a special ID in the format of A000000004..A000000150 etc and OD000000001..OD000000150. I have read the forums here and tried out the solutions (many in the form of /^([A]{1}\[0-9]{9})$/ etc.) but none of them have helped.
I hope I'm understanding your question properly, but how about this regex?
/^(A|OD)[0-9]{9}$/
To check a string against this regex, you'd use something like this:
var regex = /^(A|OD)[0-9]{9}$/;
if (regex.test(myCode)) {
// ... do something ...
}
***So the final solution to my question for people who will refer in future:
The code will be:
var regex= /^(A|OD)[0-9]{9}$/;
var myCode=document.forms["formname"]["fieldname"].value;
if(!regex.test(myCode))
{
alert(...);
return false;
}

Categories

Resources