discord.js - 如何检查用户是否在共享频道中写消息并告诉他或她在特定于机器人的频道中写
问题描述
如何检查用户是否在共享频道中写消息并告诉他在特定于机器人的频道中写?
这是我试过的代码:
if (message.channel.id === "bot-playground"){
// write code here
}else {
message.channel.send("Write commands in #bot-playground.").then(msg => {
timeout(3000, msg);
});
}
解决方案
您的问题是由if (message.channel.id === "bot-playground")
您尝试使用频道名称作为 ID 的第一行引起的。
您要么需要使用频道的 ID 来查找它,您可以通过启用Developer Mode
或者,您可以像这样使用频道名称来查找它:
message.guilds.channels.cache.find(channel => channel.name === 'bots-playground')
推荐阅读
- sharepoint - Sharepoint C#如何通过图片库的标题检索所有图片及其名称
- android - 如何使时间栏在 Android 中以 Minimal 样式工作?
- windows - Windows 上的 Clang:如何禁用默认的 MSVC 兼容性?
- javascript - 如何使用 React 中另一个组件的按钮功能调用组件中的状态更改?
- flutter - 在 Flutter 中,获取 URL 但无法在 VideoPlayer 上显示视频并出现错误
- plantuml - PlantUML:如何使动作指向动作和项目
- ruby-on-rails - Rails Pg_Search 在没有更改代码的情况下停止工作
- pca - 尝试使用 R 中的 ggbiplot 删除 PCA 中的网格线和背景
- mysql - bash: X: 参数列表太长
- sql-server - SQL 到 SAS ODBC 连接 - NVARCHAR(max) 截断但出现错误:选项 dbtype 不是有效的输出数据集选项