discord.js v14 创建频道。

6

我尝试创建一个频道,但总是出错。

不要在“code”中关注“req [0]。”,它来自数据库,与问题无关,因为它在v13中可以正常工作。

“看起来你的帖子大部分都是代码,请添加更多细节。”我不知道我还可以提供什么更多细节。哈哈。

抱歉,英语不是我的母语。

错误:

        throw new DiscordAPIError.DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
              ^

DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required
    at SequentialHandler.runRequest (/root/project/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:293:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SequentialHandler.queueRequest (/root/project/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:99:14)
    at async REST.request (/root/project/node_modules/@discordjs/rest/dist/lib/REST.cjs:52:22)
    at async GuildChannelManager.create (/root/new ascension/node_modules/discord.js/src/managers/GuildChannelManager.js:145:18) {
  rawError: {
    code: 50035,
    errors: {
      name: {
        _errors: [
          {
            code: 'BASE_TYPE_REQUIRED',
            message: 'This field is required'
          }
        ]
      }
    },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'POST',
  url: 'https://discord.com/api/v10/guilds/873350117124628552/channels',
  requestBody: {
    files: undefined,
    json: {
      name: undefined,
      topic: undefined,
      type: undefined,
      nsfw: undefined,
      bitrate: undefined,
      user_limit: undefined,
      parent_id: undefined,
      position: undefined,
      permission_overwrites: undefined,
      rate_limit_per_user: undefined,
      rtc_region: undefined,
      video_quality_mode: undefined
    }
  }
}

Node.js v18.3.0

代码:

action.guild.channels.create(`hello`, {
type: "GUILD_TEXT",
parent: cat[0].ID,
permissionOverwrites: [
{
id: bot.user.id,
allow: ['VIEW_CHANNEL', "MANAGE_CHANNELS"]
},
{
id: action.user.id,
allow: ["VIEW_CHANNEL"]
},
{
id: req[0].ID,
deny: ["VIEW_CHANNEL"]
},
{
id: staff[0].ID,
allow: ["VIEW_CHANNEL"]
}
            
]
})
1个回答

9

现在你无法再使用字符串来设置频道的类型,你必须使用新的ChannelType枚举。你可以从discord.js库中导入它,一旦导入成功,创建一个频道会像这样:

guild.channels.create({
    name: "hello",
    type: ChannelType.GuildText,
    parent: cat[0].ID,
    // your permission overwrites or other options here
});

还要确保您的所有参数都只通过一个对象传递,而名称不是单独的参数。


啊,我真笨,我知道的……谢谢你的帮助。但是错误始终都是一样的:"BASE_TYPE_REQUIRED" 这是从哪里来的? - Alexis S.
哦,抱歉,代码片段有误。所有选项都需要传递到一个对象中。我编辑了我的答案以反映这一点。 - isaac.g
@AlexisS。如果一个答案解决了你的问题,你应该点赞并接受它(打勾号),这样其他人就知道它起作用了。 - zenly
@caTS 是的!我接受了,但是我没有15点声望就不能进行点赞。 - Alexis S.
你是在导入中定义公会值还是其他什么? - Real.Cryptc
公会变量只是伪代码。它假定您正在尝试在已经具有公会变量的函数范围内使用此代码,并且该变量确实表示discord.js公会对象。 - isaac.g

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接