【问题标题】:Is there a way to bind a bot to one specific channel?有没有办法将机器人绑定到一个特定的频道?
【发布时间】:2019-12-31 12:20:21
【问题描述】:

我正在制作一个 Discord 机器人,并希望让它只能在 1 个特定频道上发帖。我不能让它的角色低于普通成员,否则将无法赋予他们角色。

我尝试了基于频道 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.')
}

我希望机器人只能在这个频道中发帖。

【问题讨论】:

  • message.channel 是一个对象。所以你正在将一个对象与一个整数进行比较(这不起作用)。试试if (message.channel.id === <channel id>) { <code here> }

标签: javascript discord discord.js


【解决方案1】:

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

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

请务必查看official documentation,了解每个类、方法、属性等的详细说明。

【讨论】:

    猜你喜欢
    • 2020-05-10
    • 2019-09-29
    • 1970-01-01
    • 2019-10-14
    • 2019-12-25
    • 2021-06-01
    • 2020-10-22
    • 2012-07-07
    • 2010-12-19
    相关资源
    最近更新 更多