potatoman23
potatoman23

Reputation: 1

How can I get a bot to respond to a channel mention?

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

Answers (3)

Adam H
Adam H

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

Jonas Wilms
Jonas Wilms

Reputation: 138257

There is message.mentions.channels for that purpose. Thats a Map, so you can check for a channel with .has().

Upvotes: 1

javajaba
javajaba

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

Related Questions