【问题标题】:Discord.js : Creating channels within CategoriesDiscord.js:在类别中创建频道
【发布时间】:2020-11-22 20:50:01
【问题描述】:

我想制作一个设计服务器的机器人,所以它的工作是制作频道和角色,这样所有者就不必浪费时间设置服务器。这是我的代码:

  if (message.content === 'tchannel') {
      message.guild.channels.create('Important', {
        type: 'category',
        permissionOverwrites: [
          {
              id: message.guild.id,
              allow: ['VIEW_CHANNEL'],
          }]
      })
      
      message.guild.channels.create('Rules', {
          type: 'text',
          permissionOverwrites: [
              {
                  id: message.guild.id,
                  allow: ['VIEW_CHANNEL'],
              }]
          })
       
  message.channel.send("Channel Created!")
    }

我想知道的是,是否有办法让文本通道连接到类别而不是单独制作?

(https://media.discordapp.net/attachments/730705963018879007/730771756784156752/lol.PNG)

【问题讨论】:

    标签: node.js discord discord.js


    【解决方案1】:

    参数cat 不需要有cat.parentID。只需输入cat 就可以了。

    示例代码:

    message.guild.channels.create('Important ', {
                    type: 'category',
                    position: 1,
                    permissionOverwrites: [
                        {
                            id: message.guild.id,
                            allow: ['VIEW_CHANNEL'],
                        }]
                }).then(cat => {
                    message.guild.channels.create('Rules', {
                        type: 'text',
                        parent: cat,
                        permissionOverwrites: [
                            {
                                id: message.guild.id,
                                allow: ['VIEW_CHANNEL'],
                            }]
                    })
    

    【讨论】:

      【解决方案2】:

      只需添加 .then 方法并从中获取 parentID。您可以将类别分配给一个变量,然后再分配它,如果您将使用它其他人。

          message.guild.channels.create('Important', {
              type: 'category',
              permissionOverwrites: [
                {
                    id: message.guild.id,
                    allow: ['VIEW_CHANNEL'],
                }]
            }).then(cat => {
              message.guild.channels.create('Rules', {
                  type: 'text',
                  parent: cat.parentID,
                  permissionOverwrites: [
                      {
                          id: message.guild.id,
                          allow: ['VIEW_CHANNEL'],
                      }]
                  })
            })
      

      【讨论】:

      • 谢谢,但遗憾的是没有用;((我使用的是 v12 btw)
      • 它不记录错误它只是使类别和文本通道分开
      【解决方案3】:

      我想你的意思是当你执行创建频道的命令时,它必须在当前频道的类别下创建它。

      如果是这样,你需要这个:

      const category = client.channels.cache.get(message.channel.parentID)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-30
        • 2023-03-27
        • 2021-04-04
        • 2020-03-05
        • 2018-04-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多