如何让不和谐机器人根据命令创建频道

时间:2021-05-25 13:51:15

标签: javascript discord discord.js

你好

我目前正在开发一个名为“文件存储”的 Discord 服务器(名称可能会发生变化) 我想知道是否有办法:当用户键入某个命令时,例如“>fs create” 机器人会创建一个类似于“channelid-storing”的频道,该频道仅对使用该命令的用户可见?

频道名称格式将显示频道ID,然后是“-storing”

let client = new Discord.Client()

client.on("message", message => {
  if(message.content === "ping") {
    message.channel.send("pong")
}
  
  client.on(message, async (message) => {
    if(message === `>fs create`){
   const channel = await message.guild.channels.create("channel", {
            permissionOverwrites: [
                {
                    id: message.guild.roles.everyone,
                    deny: ["VIEW_CHANNEL"],
                },
                {
                    id: message.member,
                     allow: [
                        "VIEW_CHANNEL",
                        "SEND_MESSAGES",
                        "EMBED_LINKS",
                        "ATTACH_FILES",
                        "READ_MESSAGE_HISTORY",
                    ],
                },
                {
                    id: message.guild.me, 
                    allow: [
                        "VIEW_CHANNEL",
                        "SEND_MESSAGES",
                        "EMBED_LINKS",
                        "ATTACH_FILES",
                        "READ_MESSAGE_HISTORY",
                    ],
                },
            ],
        });
    channel.editName(`${channel.id}-store`)

}
})
    
})

client.login(process.env.DISCORD_TOKEN);```

1 个答案:

答案 0 :(得分:1)

您只需要在创建频道时提供用户权限

if(commandname === `> fs create`){
   const channel = await message.guild.channels.create("channelname", {
            permissionOverwrites: [
                {
                    id: message.guild.roles.everyone,
                    deny: ["VIEW_CHANNEL"],
                },
                {
                    id: message.member,
                     allow: [
                        "VIEW_CHANNEL",
                        "SEND_MESSAGES",
                        "EMBED_LINKS",
                        "ATTACH_FILES",
                        "READ_MESSAGE_HISTORY",
                    ],
                },
                {
                    id: message.guild.me, 
                    allow: [
                        "VIEW_CHANNEL",
                        "SEND_MESSAGES",
                        "EMBED_LINKS",
                        "ATTACH_FILES",
                        "READ_MESSAGE_HISTORY",
                    ],
                },
            ],
        });
    channel.editName(`${channel.id}-store`)

}

顺便说一句,你必须添加你的东西,这样它才能正常工作,上面的例子展示了频道创建是如何工作的..