Responding to a message in discord.js

If you want to use the read function there two ways

As @SickBoy Said,

function read(msg){
if(msg.content.startsWith('s#'){
return true;
}
else{
return false;
}
}

or else,

function read(msg){
const data = msg.content.split('')
if(data[0] === 's' && data[1] === '#'){
return true;
}
else{
return false;
}
}

To call this function simply add a event of message.

client.on('message' , message=> {
const res = read(message)
if(res){
//The message starts with s#
}
else{
//It doesn't start with s#
}
})

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top