discord.js - 检查消息是否有频道提及
问题描述
我不知道使用什么方法来检查消息是否包含对频道的提及;如果是,我想继续执行,如果不是,返回错误消息。
if (message.mentions.channels == true) {
console.log('Yeah, you used a channel mention');
} else {
console.log('Hey boy, you have to use a channel mention');
}
有人可以消除我的疑问吗?
解决方案
您可以使用Collection.first()
来查看集合是否至少有 1 个元素(这意味着消息至少有 1 个频道提及)。
它应该如下所示:
if (message.mentions.channels.first()) console.log("You used a channel mention.");
else console.log("You didn't.");
推荐阅读
- r - 当我尝试在特殊网格上绘制点时,为什么 ggmap plot 说只有缺失值?
- javafx - 记录 TestFX 的 UI 元素
- mysql - Mysql查询计算列中的常见数字
- java - android TV 通过索引以编程方式选择 BrowseSupportFragment/RowsSupportFragment 的项目
- wordpress - Wordpress 圣人引导程序不起作用
- typo3 - 在 TYPO3 的查询中获取不需要的 where 子句
- python - 如何比较包含整数的列表 A 和列表 B 并打印缺失的整数?
- c# - 使用 NoAuth 的 Web 请求
- c# - 为模型绑定到集合类型指定相等比较器
- sql - 如何在一行SQL中合并多行