Reputation: 1
I have a bot that is used for archiving and organization of channels. I am trying to get it to perform some code when someone mentions a channel so that it moves the message to the channel it belongs in but I can't get it to respond to the channel mention.
I thought it would be something like this
if (message.content == "<#ChannelID>") {
do things
}
Upvotes: 0
Views: 462
Reputation: 1818
Here is an approach I would take as I mentioned in my comment.
// array of channels that you are monitoring and looking for
const channelList = [
{name: 'Channel1', roomId: 1},
{name: 'Channel2', roomId: 2},
{name: 'Channel3', roomId: 3},
{name: 'Channel4', roomId: 4},
{name: 'Channel5', roomId: 5},
]
function test() {
let msg = document.getElementById('test').value || '';
console.log('mentioned channels', channelList.filter(channel => msg.toLowerCase().indexOf(channel.name.toLowerCase()) > -1))
}
<span>Type your sample message in the textbox and click test.</span><br />
<input type="text" id="test" />
<button onclick="test()">test</button>
Upvotes: 0
Reputation: 138257
There is message.mentions.channels
for that purpose. Thats a Map, so you can check for a channel with .has()
.
Upvotes: 1
Reputation: 85
You probably want to use the includes
method.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes
Upvotes: 0