首页 > 解决方案 > 检查消息是否有频道提及

问题描述

我不知道使用什么方法来检查消息是否包含对频道的提及;如果是,我想继续执行,如果不是,返回错误消息。

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');
}

有人可以消除我的疑问吗?

标签: discord.js

解决方案


您可以使用Collection.first()来查看集合是否至少有 1 个元素(这意味着消息至少有 1 个频道提及)。
它应该如下所示:

if (message.mentions.channels.first()) console.log("You used a channel mention.");
else console.log("You didn't.");

推荐阅读