【问题标题】:discord.js How do i make a bot talk in a specific channeldiscord.js 如何让机器人在特定频道中说话
【发布时间】:2019-12-25 09:32:40
【问题描述】:

我正在发布一个公告命令,当管理员执行 -announce(文本)时,它将在名为公告的频道中宣布它,我该怎么做?

【问题讨论】:

    标签: chat bots discord discord.js


    【解决方案1】:

    在标准实现中,你可以这样做

      bot.on('message', message => {
        if(message.content.startsWith('-announce') && message.member.hasPermission("ADMINISTRATOR")) {
            let announceChannel = bot.channels.get('YOUR ChannelID')
            if(!announceChannel) return
            announceChannel.send(message.content.substr(10,message.content.length))  //10 its length of you command
    }})
    

    【讨论】:

      【解决方案2】:

      按名称获取频道:

      const Channel = client.channels.find(channel => channel.name === "announcements");
      

      client.channelsCollection

      使用GuildChannel.send()方法发送消息:

      Channel.send("your announcement here");
      

      【讨论】:

        猜你喜欢
        • 2021-02-02
        • 2020-11-10
        • 2020-09-25
        • 1970-01-01
        • 2020-05-10
        • 2021-06-10
        • 1970-01-01
        • 2020-10-04
        • 1970-01-01
        相关资源
        最近更新 更多