如何在discord.js v14中创建频道

问题描述 投票:0回答:1

我似乎无法创建频道,我发现的代码都不起作用,请告诉我怎么做

client.on('messageCreate', async (msg) => { 
  if (msg.content === '$setup') {
      msg.reply('Setup command received');

      msg.guild.channels.create({
          name: "new-channel",
          type: "text",
          permissionOverwrites: [
              {
                  id: msg.guild.id,
                  accept: [PermissionsBitField.Flags.ViewChannel],
              },
          ],
      });
  }

我希望这会创建频道,但它只是给出:

/home/runner/MegaBot/node_modules/@discordjs/rest/dist/index.js:722
      throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
            ^

DiscordAPIError[50035]: Invalid Form Body
type[NUMBER_TYPE_COERCE]: Value "text" is not int32.
    at handleErrors (/home/runner/MegaBot/node_modules/@discordjs/rest/dist/index.js:722:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SequentialHandler.runRequest (/home/runner/MegaBot/node_modules/@discordjs/rest/dist/index.js:1120:23)
    at async SequentialHandler.queueRequest (/home/runner/MegaBot/node_modules/@discordjs/rest/dist/index.js:953:14)
    at async _REST.request (/home/runner/MegaBot/node_modules/@discordjs/rest/dist/index.js:1266:22)
    at async GuildChannelManager.create (/home/runner/MegaBot/node_modules/discord.js/src/managers/GuildChannelManager.js:171:18) {
  requestBody: {
    files: undefined,
    json: {
      name: 'new-channel',
      topic: undefined,
      type: 'text',
      nsfw: undefined,
      bitrate: undefined,
      user_limit: undefined,
      parent_id: undefined,
      position: undefined,
      permission_overwrites: [ { id: '1157099244453376162', type: 0, allow: '0', deny: '0' } ],
      rate_limit_per_user: undefined,
      rtc_region: undefined,
      video_quality_mode: undefined,
      default_thread_rate_limit_per_user: undefined,
      available_tags: undefined,
      default_reaction_emoji: undefined,
      default_auto_archive_duration: undefined,
      default_sort_order: undefined,
      default_forum_layout: undefined
    }
  },
  rawError: {
    message: 'Invalid Form Body',
    code: 50035,
    errors: {
      type: {
        _errors: [
          {
            code: 'NUMBER_TYPE_COERCE',
            message: 'Value "text" is not int32.'
          }
        ]
      }
    }
  },
  code: 50035,
  status: 400,
  method: 'POST',
  url: 'https://discord.com/api/v10/guilds/1157099244453376162/channels'
}

Node.js v20.10.0

我使用的是discord.js v14.14.1,我基本上到处搜索都找不到解决方案。

javascript discord discord.js
1个回答
0
投票

类型必须是数字。 0 是文本,但您也可以使用 discord.js 中的

ChannelType.GuildText
,它更具可读性,但与 0

相同
© www.soinside.com 2019 - 2024. All rights reserved.