首页 > 解决方案 > 如何检查用户是否在共享频道中写消息并告诉他或她在特定于机器人的频道中写

问题描述

如何检查用户是否在共享频道中写消息并告诉他在特定于机器人的频道中写?

这是我试过的代码:

if (message.channel.id === "bot-playground"){
    // write code here
}else {
    message.channel.send("Write commands in #bot-playground.").then(msg => {
        timeout(3000, msg);
    });
}

标签: discord.jschanneltransmission

解决方案


您的问题是由if (message.channel.id === "bot-playground")您尝试使用频道名称作为 ID 的第一行引起的。

您要么需要使用频道的 ID 来查找它,您可以通过启用Developer Mode

或者,您可以像这样使用频道名称来查找它:

message.guilds.channels.cache.find(channel => channel.name === 'bots-playground')


推荐阅读