javascript - 有没有一种方法可以将机器人绑定(bind)到一个特定的 channel ?

标签 javascript discord discord.js

我正在制作一个 Discord 机器人,并希望使其只能在 1 个特定 channel 上发布。我不能让它的 Angular 色比普通成员(member)低,否则就无法给他们 Angular 色。

我尝试了基于 channel ID 的 if/else 语句。

case 'start':
if (message.channel === 615842616373805067) {
   //somewhat unimportant command
    return message.member.addRole('615166824849604619'), 
    message.channel.send(` ${message.author} has been given the role.)`, 
    message.delete);
    //unimportant command ends here
} else { 
    console.log('Wrong channel, no role.')
}

我希望机器人只能在这一个 channel 中发帖。

最佳答案

不要检查 message.channel 类,而是尝试检查该类的 id 属性

if(message.channel.id != "615842616373805067") return console.log('Wrong channel, no role.');
//rest of your code

请务必检查official documentation有关每个类、方法、属性等的详细说明

关于javascript - 有没有一种方法可以将机器人绑定(bind)到一个特定的 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57672630/

相关文章:

javascript - 将多条记录添加到本地存储

javascript - 如何从json渲染mustache js

python - 导入错误: cannot import name 'Deque'

javascript - Replit Discord 机器人不断关闭

javascript - 为什么我突然收到 ELIFECYCLE errno 1?

javascript - 在 discord.js 中发送文件缓冲区

javascript - 客户端到服务器端谷歌分析 MP 客户端 ID

python - (Python) Discord bot 从语音聊天中断开连接

javascript - 如何使我的命令不提及用户?

javascript - forEach() 不会更新数据库调用内的值