discord.js如何在特定频道进行机器人对话

时间:2019-12-24 19:16:39

标签: chat bots discord discord.js

我正在执行公告命令,当管理员执行-announce(文本)操作时,它将在称为公告的频道中进行公告,我该怎么做?

2 个答案:

答案 0 :(得分: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
}})

答案 1 :(得分:0)

通过名称获取频道:

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

client.channelsCollection

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

Channel.send("your announcement here");