繁体   English   中英

如何获得漫游器来回应频道提及?

[英]How can I get a bot to respond to a channel mention?

我有一个用于存档和组织频道的机器人。 我试图让它在有人提及某个频道时执行一些代码,以便将消息移至其所属的频道,但是我无法使其响应该频道提及。

我以为会是这样

if (message.content == "<#ChannelID>") {
            do things  
    }

为此目的有message.mentions.channels 那就是一张地图,因此您可以使用.has()检查频道。

正如我在评论中提到的,这是我将采取的一种方法。

 // 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> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM